I am interested in directly reading (sourcing) R scripts from a multi-user web-based codesharing site. I have not found any sites which store code in a format that is accessible to R (which may very well be due to my ignorance). I have tried a workaround in which I download a GoogleDoc to a .txt and then source it from my local machine, but there seems to be an encoding issue that I don't understand. I have searched for solutions but have not found anything that is current.
(1) Does anyone have specific solutions for how to accomplish a direct source()-like operation from an online code editor (e.g. codeshare.io, kobra.io, etc)? To be clear, I want to be able to read in scripts from shared coding sessions and run them on my local machine in one or two keystrokes. I am not interested in github.
(2) If not, can anyone tell me why the following code snippet fails to source, and what I must do to correct the error?
Example...
dl_from_GoogleD <- function(output, key, format) {
require(RCurl)
bin <- getBinaryURL(paste0("https://docs.google.com/document/d/", key, "/export?format=", format), ssl.verifypeer = FALSE)
con <- file(output, open = "wb")
writeBin(bin, con)
close(con)
message(noquote(paste(output, "read into", getwd())))
}
setwd(tempdir())
dl_from_GoogleD(output = "test.txt", key = "11jYc5uvDOWrHmYRXOJtLsycxvojiW4qIN6aVQsJCYQM", format = "txt")
source("test.txt", echo=T)
Error received: Error in source("test.txt", echo = T) : test.txt:1:2: unexpected input 1: ï» ^
I'm running Windows 7 and RStudio.