R code on Google docs

Viewed 5684

I'm aware that you can publish spreadsheets on Google docs and then import them in R. However, let's say I have a function or some code I want to read in R (like in the source function). How would you for example read in all this code stored on google docs?

https://docs.google.com/document/edit?id=1f11rcVs9AtVcgOyiP0lV04yq9hshVDIPx93lA0ItFvQ

I don't think this has been published but it's just to give an example.

Basically I want to:

  1. Create a function in R (for comparability see example below)

  2. Upload it on Google Docs and share it with anyone with the link so that I don't have to log in through R or Google Docs etc...

  3. Read it in through a command like source() wherever I want

My interest is not in reading data but in reading functions. It would make importing my own functions much quicker when I'm not on the same computer/server.

Any ideas?

Many thanks

P.S. Example of a function from statsmethods.net

mysummary <- function(x,npar=TRUE,print=TRUE) {
  if (!npar) {
    center <- mean(x); spread <- sd(x) 
  } else {
    center <- median(x); spread <- mad(x) 
  }
  if (print & !npar) {
    cat("Mean=", center, "\n", "SD=", spread, "\n")
  } else if (print & npar) {
    cat("Median=", center, "\n", "MAD=", spread, "\n")
  }
  result <- list(center=center,spread=spread)
  return(result)
}
4 Answers
Related