Folder management with r : Check existence of directory and create it if it doesn’t exist

Use showWarnings = FALSE: dir.create(file.path(mainDir, subDir), showWarnings = FALSE) setwd(file.path(mainDir, subDir)) dir.create() does not crash if the directory already exists, it just prints out a warning. So if you can live with seeing warnings, there is no problem with just doing this: dir.create(file.path(mainDir, subDir)) setwd(file.path(mainDir, subDir))

Deploying R shiny app as a standalone application [closed]

There is now a way to turn a Shiny app into a standalone Electron app (which is a desktop app, used for apps like Slack). To find out more, see this excellent presentation (YouTube) from useR 2018, which contains further links: GitHub ColumbusCollaboratory: electron-quick-start GitHub ColumbusCollaboratory: Photon. RStudio Add-in to build Shiny apps utilizing the … Read more

How to draw a nice arrow in ggplot2

Here are some reproducible examples (try running them) A Simple arrow (i.e. line segment): library(dplyr) library(ggplot2) # Create a scatter plot i <- ggplot(mtcars, aes(wt, mpg)) + geom_point() # Add arrow i + geom_segment(aes(x = 5, y = 30, xend = 3.5, yend = 25), arrow = arrow(length = unit(0.5, “cm”))) A Simple curved arrow … Read more

How to pass command-line arguments when calling source() on an R file within another R file

I assume the sourced script accesses the command line arguments with commandArgs? If so, you can override commandArgs in the parent script to return what you want when it is called in the script you’re sourcing. To see how this would work: file_to_source.R print(commandArgs()) main_script.R commandArgs <- function(…) 1:3 source(‘file_to_source.R’) outputs [1] 1 2 3 … Read more