导入来自互联网站的脚本

huangapple go评论77阅读模式
英文:

R: Import scripts from internet site

问题

I wondering if its possible import or read scripts from a internet site, I would like import scripts from:
http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/

I did try with

setwd("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/")

or

script=source("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")

But gave me an error.
Thanks in advance

我想知道是否可以从互联网站导入或读取脚本,我想要导入来自以下网址的脚本:
http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/

我尝试过以下方式:

setwd("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/")

或者

script=source("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")

但是出现了错误。
提前感谢。

英文:

I wondering if its possible import or read scripts from a internet site, I would like import scripts from:
http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/

I did try with

setwd("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/")

or

script=source("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")

But gave me an error.
Thanks in advance

答案1

得分: 1

这些看起来像是需要互动使用的文件(例如,在RStudio中打开它们),因为它们包含到文件的绝对链接(例如 read.table("c:/Work08/StatDesignSC08/Data/Alfalfa.txt", sep = "", header = TRUE))。我建议您下载它们,然后打开。例如,使用以下命令:

source_file <- "http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/Alfalfa.R"

download.file(url = source_file, destfile = basename(source_file))

file.edit(basename(source_file))

然后编辑您需要的路径。否则,您将不断遇到“无法打开文件”的错误。

英文:

These look like files that you need to use interactively (e.g., open them in RStudio) as they contain absolute links to files (e.g. read.table(&quot;c:/Work08/StatDesignSC08/Data/Alfalfa.txt&quot;,sep = &quot;&quot;,header=T)). I would suggest you download them and then open them. For example using these commands:

source_file &lt;- &quot;http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/Alfalfa.R&quot;

download.file(url = source_file, destfile = basename(source_file))

file.edit(basename(source_file))

And then edit the paths you need. Otherwise you will constatntly run into cannot open file errors.

答案2

得分: 0

你可以使用devtools包中的source_url函数。

library(devtools)
source_url("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")

请注意,在Windows上,这也应该有效:

source("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")
英文:

You can use the function source_url from devtools package.

library(devtools)  
source_url(&quot;http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R&quot;)

Please note that on windows this should also work:

source(&quot;http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R&quot;)

huangapple
  • 本文由 发表于 2020年1月6日 22:58:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614286.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定