我无法访问互联网。因此,我从其他系统下载了sqldf包,然后将其传输到该系统。
sqldf_0.4-10.tar文件保存在“C:\ Users \ Riya \ Documents \ R”中,并且还将二进制文件保存在同一文件夹中。我想安装包含依赖项的包。当我使用“包”下拉列表中的“从本地zip文件安装包”安装包时。它不是安装依赖项。我用google搜索解决方案,发现:
tools::write_PACKAGES("C:/Users/Riya/Documents/R/")
之后,
install.packages("sqldf", repos="file://C:/Users/Riya/Documents/R/")
它给了我一个错误 -
source repository is unavailable to check versions
Error in read.dcf(file = tmpf) : cannot open the connection
In addition: Warning message:
In read.dcf(file = tmpf) :
cannot open compressed file '//C:/Users/Riya/Documents/R/bin/windows/contrib/3.1/PACKAGES', probable reason 'No such file or directory'>
这是一个窗口系统。
注意:tools::write_PACKAGES()
创建2个文件。我还根据论坛中提到的解决方案删除了“PACKAGES.gz”文件。
答案 0 :(得分:4)
从R控制台,您可以使用:
install.packages("C:/Users/Riya/Documents/R/sqldf_0.4-10.tar", repos=NULL, type="source")
您也可以从OS命令行安装,使用R CMD INSTALL作为G. Grothendieck在评论中写道。
答案 1 :(得分:-1)
从R [Windows 7 32位和RGui(32位)i386 3.3.0]中的本地zip文件安装多个软件包
*我不习惯在R中,甚至Stack。
我们以简单的方式做到了---
运行以下R命令
install.packages(file.choose(), repos=NULL)
file.choose()
命令将显示一个窗口,允许您选择.zip
文件或下载它的tar.gz
文件。现在我们尝试从本地驱动器安装多个软件包---
在R控制台中运行以下命令 -
result <- array(list.files(path = "D:/Backup/R tutorial/downloaded_packages", pattern = "*.zip", all.files = FALSE, full.names = FALSE, recursive = FALSE))
result
将zip文件名列表存储在数组中,直到以任何方式替换值或关闭RGui(工作空间)。path = "..."
替换您自己的驱动路径。pattern = "..."
可能会替换"tar.gz"
,但我尚未对其进行测试。现在运行循环来安装所有zip文件:
for(i in 1:length(result)) {
x <- paste("D:/Backup/R tutorial/downloaded_packages/",result[i], sep="", collapse = NULL)
print(i)
print(result[i])
install.packages(x, repos = NULL, type = "win.binary")
# readline(prompt="Press [enter] to continue")
}
x
我们存储文件名,paste
帮助我做到这一点。install.packages(x, repos = NULL, type = "win.binary")
逐个安装zip文件。readline
从用户那里获取输入以继续循环。在这里,我通过#
正常循环执行 -
[1] 7402
[1] "RKEELdata_1.0.3.zip"
Installing package into ‘C:/Users/Amitava Kar/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
常见错误和退出循环 -
[1] 7403
[1] "RKEELjars_1.0.15.zip"
Installing package into ‘C:/Users/Amitava Kar/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
cannot open the connection
In addition: Warning messages:
1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
cannot open compressed file 'RKEELjars/DESCRIPTION', probable reason 'No such file or directory'
print(i)
显示数组读取次数,例如[1] 7403
print(result[i])
显示zip文件,例如[1] "RKEELjars_1.0.15.zip"
现在手动下载并替换zip文件并更改循环
for(i in 1:length(result))
for(i in 7403:length(result))
并重新运行
程序再次,例如。
for(i in 7403:length(result)) {
x <- paste("D:/Backup/R tutorial/downloaded_packages/",result[i], sep="", collapse = NULL)
print(i)
print(result[i])
install.packages(x, repos = NULL, type = "win.binary")
# readline(prompt="Press [enter] to continue")
}