Google文档上的R代码 [英] R code on Google docs

查看:61
本文介绍了Google文档上的R代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以在Google文档上发布电子表格,然后将其导入R中.但是,假设我有一个函数或一些我想在R中读取的代码(例如在源函数中).例如,您将如何阅读存储在Google文档中的所有这些代码?

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

我不认为这已经发表过,但这只是举一个例子.

基本上我想:

  1. 在R中创建一个函数(有关可比性,请参见下面的示例)

  2. 将其上传到Google Docs上并与任何具有链接的人共享,这样我就不必通过R或Google Docs等登录.

  3. 在任何需要的地方通过诸如source()之类的命令读取它

我的兴趣不是读取数据,而是读取功能.如果我不在同一台计算机/服务器上,则可以更快地导入自己的功能.

有什么想法吗?

非常感谢

P.S.statsmethods.net中的功能示例

  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)返回(结果)} 

使用Dropbox最容易完成-参见

但是您可以使用Googledocs进行操作,例如此处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)
}

解决方案

It is most easily done with Dropbox - see here http://thebiobucket.blogspot.co.at/2012/05/source-r-script-from-dropbox.html

like so:

source("http://dl.dropbox.com/s/c18lcwnnrodsevt/test_dropbox_source.R")

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

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 = ""))

这篇关于Google文档上的R代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆