首页 > 解决方案 > R:从网站导入脚本

问题描述

我想知道它是否可能从互联网站点导入或读取脚本,我想从以下位置导入脚本: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")

但是给了我一个错误。提前致谢

标签: rimport

解决方案


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

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

然后编辑您需要的路径。否则,您将不断遇到cannot open file错误。


推荐阅读