Google文档上的R代码 [英] R code on Google docs
问题描述
我知道您可以在Google文档上发布电子表格,然后将其导入R中.但是,假设我有一个函数或一些我想在R中读取的代码(例如在源函数中).例如,您将如何阅读存储在Google文档中的所有这些代码?
https://docs.google.com/document/edit?id=1f11rcVs9AtVcgOyiP0lV04yq9hhVDIPx>> 我不认为这已经发表过,但这只是举一个例子. 基本上我想: 在R中创建一个函数(有关可比性,请参见下面的示例) 将其上传到Google Docs上并与任何具有链接的人共享,这样我就不必通过R或Google Docs等登录. 在任何需要的地方通过诸如source()之类的命令读取它 我的兴趣不是读取数据,而是读取功能.如果我不在同一台计算机/服务器上,则可以更快地导入自己的功能. 有什么想法吗? 非常感谢 P.S.statsmethods.net中的功能示例 使用Dropbox最容易完成-参见 但是您可以使用Googledocs进行操作,例如此处 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: Create a function in R (for comparability see example below) 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... 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
It is most easily done with Dropbox - see here http://thebiobucket.blogspot.co.at/2012/05/source-r-script-from-dropbox.html like so: But you can either do it with Googledocs, like here http://thebiobucket.blogspot.co.at/2011/11/how-to-run-r-scripts-directly-out-of.html#more
这篇关于Google文档上的R代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
mysummary<-函数(x,npar = TRUE,print = TRUE){如果(!npar){中心<-均值(x);扩展<-sd(x)} 别的 {中心<-中位数(x);传播<-mad(x)}如果(print&!npar){cat(平均值=,中心," \ n," SD =,展开," \ n)} else if(print& npar){cat("Median =",center,"\ n","MAD =",spread,"\ n")}结果<-列表(center = center,spread = spread)返回(结果)}
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)
}
source("http://dl.dropbox.com/s/c18lcwnnrodsevt/test_dropbox_source.R")
library(RCurl)
setwd(tempdir())
destfile = "test_google_docs.txt"
x = getBinaryURL("https://docs.google.com/uc?export=download&id=0B2wAunwURQNsMDViYzllMTMtNjllZS00ZTc4LTgzMzEtNDFjMWQ3MTUzYTRk", followlocation = TRUE, ssl.verifypeer = FALSE)
writeBin(x, destfile, useBytes = TRUE)
source(paste(tempdir(), "/test_google_docs.txt", sep = ""))