如何使用github的R脚本?

时间:2016-03-01 10:38:34

标签: r github leaflet.draw

我尝试使用github plugin-draw.R创建的源码如何使用这个blugin?

4 个答案:

答案 0 :(得分:5)

您可以使用R-Bloggers上提供的解决方案:

source_https <- function(u, unlink.tmp.certs = FALSE) {
  # load package
  require(RCurl)

  # read script lines from website using a security certificate
  if(!file.exists("cacert.pem")) download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile = "cacert.pem")
  script <- getURL(u, followlocation = TRUE, cainfo = "cacert.pem")
  if(unlink.tmp.certs) unlink("cacert.pem")

  # parase lines and evealuate in the global environement
  eval(parse(text = script), envir= .GlobalEnv)
}

source_https("https://raw.github.com/tonybreyal/Blog-Reference-Functions/master/R/bingSearchXScraper/bingSearchXScraper.R")
source_https("https://raw.github.com/tonybreyal/Blog-Reference-Functions/master/R/htmlToText/htmlToText.R", unlink.tmp.certs = TRUE)

对于要在全局环境中评估的函数(我猜你更喜欢这个解决方案)你可以使用:

{{1}}

正如the original article Tony Breyal中提到的那样,this discussion on SO也应该被记入,因为它与讨论的问题相关。

答案 1 :(得分:3)

您可以只使用软件包import sncosmo import pandas as pd days_apart = list(range(55, 300)) model = sncosmo.Model(source="hsiao") model.set(z=1.5, t0=100) y = model.bandmag('desr', 'ab', days_apart) df = pd.DataFrame([y]) for i, j in enumerate(range(6,300)): df1 = df.iloc[:,i:j+1] with open("test_data.csv", "a") as f: df1.to_csv(f, header=False) 中的source_url

devtools

答案 2 :(得分:2)

如果是 GitHub 上的链接,您可以点击 Raw 旁边的 Blame,实际上您可以使用普通的 base::source。转到您选择的 R 脚本并找到 Raw 按钮。

enter image description here

链接现在将包含 raw.githubusercontent.com,并且页面只显示 R 脚本本身。那么,对于这个例子,

source(
  paste0(
    "https://raw.githubusercontent.com/betanalpha/knitr_case_studies/master/", 
    "stan_intro/stan_utility.R"
  )
)

(使用 paste0 只是为了使 URL 适合更窄的屏幕。)

答案 3 :(得分:0)

基于@Matifou's reply,但使用“ new”方法在URL末尾附加了?raw=TRUE

devtools::source_url("https://github.com/tonybreyal/Blog-Reference-Functions/blob/master/R/bingSearchXScraper/bingSearchXScraper.R?raw=TRUE")