Wednesday, June 5, 2013

Running R Scripts Directly From Dropbox

I have written a little function that allows users to run R scripts out of Dropbox directly from any location.  It was aided by this post on biobucket.  The reason I am particularly interested in this feature is because I am often using a server to run my R code.  This otherwise would require me to upload my R script directly to the server every time I make a change.  However, I can instantly test my code on the server by having it run the code remotely since dropbox is very good at detecting changes and updating its database instantly.

# Evaluate code directly from a dropbox file
dropbox.eval <- function(x, noeval=F) {
  # Load the file into memory as a text file with getURL
  intext <- getURL(paste0("",x), 
                        ssl.verifypeer = FALSE)
  # For some reason \r seem to be frequently inserted into 
  #   the script files that I save.  They present a problem
  #   so I remove them using gsub.
  intext <- gsub("\r","", intext)
  # Evaluate the input file.
  if (!noeval) eval(parse(text = intext), envir= .GlobalEnv)
  # Finally return the dropbox script as text.
Highlighted by Pretty R at

I also found that there is a R package built specifically for interfacing with dropbox which looks pretty great at  I have not yet implemented it.

This command can also be found at

I am starting work on a package (RConcerto) meant to provide tools for helping in the production of Concerto online tests.  It also includes tools for generating HTML objects.  More on this in the future.

No comments:

Post a Comment