英文:
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("c:/Work08/StatDesignSC08/Data/Alfalfa.txt",sep = "",header=T)
). I would suggest you download them and then open them. For example using these commands:
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))
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("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")
Please note that on windows this should also work:
source("http://archived.stat.ufl.edu/casella/StatDesign/WebRPrograms/FishTank.R")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论