I know it’s possible to publish spreadsheets on Google Docs and import them into R. However, what if I want to read a specific R function or piece of code directly from Google Docs? For instance, I wish to write a function in R, upload it to Google Docs, and share it so others can access it without needing to log in. My goal is to then retrieve it using a command similar to source()
at any time. I am particularly interested in importing functions rather than data, as it would expedite the process of using my custom functions on different devices.
Here’s an example of a function I might want to upload:
myStatsFunction <- function(data, isNonParametric=TRUE, display=TRUE) {
if (!isNonParametric) {
avg <- mean(data)
variability <- sd(data)
} else {
avg <- median(data)
variability <- mad(data)
}
if (display && !isNonParametric) {
cat("Average=", avg, "\n", "Standard Deviation=", variability, "\n")
} else if (display && isNonParametric) {
cat("Median=", avg, "\n", "MAD=", variability, "\n")
}
return(list(average=avg, variability=variability))
}
Does anyone have suggestions on how I can accomplish this?