如何手动或离线从github安装R包

时间:2015-04-01 11:37:46

标签: r github download package

我尝试从github下载tsdyn软件包(它还没有更新)但我的代理阻止我连接到github。

library(devtools)
install_github("MatthieuStigler/tsDyn", ref="Dev94", subdir="tsDyn") 

Downloading github repo MatthieuStigler/tsDyn@Dev94
Erreur dans function (type, msg, asError = TRUE)  : 
Failed to connect to api.github.com port 443: Connection refused

然后我下载了.zip并尝试从.zip安装软件包并出现此错误:

Erreur dans read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",     "Type")) : 
impossible d'ouvrir la connexion
De plus : Message d'avis :
In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) :
impossible d'ouvrir le fichier compressé 'tsDyn-master/DESCRIPTION', cause probable : 'No such file or directory' 

我不明白,因为我可以在存储库中找到DESCRIPTION文件。 我认为它正试图连接到互联网,这是我的专业联系所不允许的。 我发现有些Linux用户成功通过另一个端口下载而不是443(必须允许端口8000我想但不确定)但我有Windows 7。 我有管理员凭据,当我尝试使用R作为管理员时,它不起作用。 我真的对代理配置一无所知,所以如果您有任何想法,请尝试更具体地说明我应该采取的行动。

非常感谢提前!

Edit1:我尝试了你的提议,并删除了文件库中不必要的级别,我做了一个

Rscript -e "install.packages ('C:/Users/stephanie/Downloads/tsDyn.zip',repos=NULL) " 

我从终端“将软件包安装到'C:/Users/stephanie/Documents/R/win-library/3.1'(由于'lib'未指定)。它似乎工作但是当我使用命令时在RI的图书馆(tsDyn)得到了“Erreur dans library(tsDyn),'tsDyn'n'est pas un nom correct depackageinstallé”(我猜不是英文安装包的正确名称)。虽然,文件存在于win-library但我注意到其他包目录中始终存在的文件MD5和INDEX在这里不存在。想法?

Edit2:我找到了一个解决方案,根据建议删除了不必要的级别,我接下来使用devtools的安装功能并且它工作(离线)......

library(devtools)
install("C:/Users/stephanie/Downloads/tsDyn")

我真的不明白与终端命令的区别所以,如果有人能给我线索,我已经解决了我的pb,但我有兴趣了解如何!

3 个答案:

答案 0 :(得分:1)

将所有内容都移到一个级别,这样您就没有名为tsDyn的中间文件夹,然后可以:

install_github("MatthieuStigler/tsDyn")

或保留原样和

install_github("MatthieuStigler/tsDyn/tsDyn")

证据在布丁中

library(devtools)
install_github("MatthieuStigler/tsDyn/tsDyn")

    # Downloading github repo MatthieuStigler/tsDyn@master
# Installing tsDyn
# "C:/PROGRA~1/R/R-31~1.2/bin/x64/R" --vanilla CMD INSTALL  \
#   "C:/Users/dominic/AppData/Local/Temp/RtmpiwFHUz/devtools30d0779d2870/MatthieuStigler-tsDyn-8048816/tsDyn"  \
#   --library="D:/Copy/R/win-library/3.1" --install-tests 
# 
# * installing *source* package 'tsDyn' ...
# ** libs
# 
# *** arch - i386
# gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O3 -Wall  -std=gnu99 -mtune=core2 -c llar.c -o llar.o
# gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O3 -Wall  -std=gnu99 -mtune=core2 -c misc.c -o misc.o
# gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O3 -Wall  -std=gnu99 -mtune=core2 -c search.c -o search.o
# gcc -m32 -shared -s -static-libgcc -o tsDyn.dll tmp.def llar.o misc.o search.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.2/bin/i386 -lR
# installing to D:/Copy/R/win-library/3.1/tsDyn/libs/i386
# 
# *** arch - x64
# gcc -m64 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -std=gnu99 -mtune=core2 -c llar.c -o llar.o
# gcc -m64 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -std=gnu99 -mtune=core2 -c misc.c -o misc.o
# gcc -m64 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG     -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -std=gnu99 -mtune=core2 -c search.c -o search.o
# gcc -m64 -shared -s -static-libgcc -o tsDyn.dll tmp.def llar.o misc.o search.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.2/bin/x64 -lR
# installing to D:/Copy/R/win-library/3.1/tsDyn/libs/x64
# ** R
# ** data
# ** inst
# ** tests
# ** preparing package for lazy loading
# ** help
# *** installing help indices
# ** building package indices
# ** installing vignettes
# ** testing if installed package can be loaded
# *** arch - i386
# *** arch - x64
# * DONE (tsDyn)

library(tsDyn)
tsDyn::autopairs

# function (x, lag = 1, h, type = c("levels", "persp", "image", 
#     "lines", "points", "regression")) 
# {
#     panel <- list(levels = function() sm::sm.density(X, h = rep(h, 
#         2), xlab = xlab, ylab = ylab, main = "density", display = "slice"), 
#         persp = function() sm::sm.density(X, h = rep(h, 2), xlab = xlab, 
#             ylab = ylab, main = "density", display = "persp"), 
#         image = function() sm::sm.density(X, h = rep(h, 2), xlab = xlab, 
#             ylab = ylab, main = "density", display = "image"), 
#         lines = function() plot(X, xlab = xlab, ylab = ylab, 
#             main = "lines", type = "l"), points = function() plot(X, 
#             xlab = xlab, ylab = ylab, main = "scatter"), regression = function() sm::sm.regression(X[, 
#             1], X[, 2], h = h, xlab = xlab, ylab = ylab, main = "regression", 
#             ask = FALSE))
#     lags <- c(-lag, 0)
#     X <- embedd(x, lags = lags)
#     xlab <- paste("lag", lag)
#     ylab <- paste("lag", 0)
#     type <- match.arg(type)
#     if (missing(h)) {
#         h <- sm::hnorm(X)[1]
#     }
#     panel[[type]]()
# }
# <environment: namespace:tsDyn>

答案 1 :(得分:1)

您可以通过在防火墙后工作时设置代理来避免这种情况。从Rstudio设置代理的说明在Link中。

  1. 请咨询您的IT管理员,在内部网络上使用哪种代理来访问HTTP / HTTPS?在大多数情况下,它会  HTTP - http://proxy.companydomain:8080  HTTPS - https://proxy.companydomain:8080
  2. 找到 Renviron.site 文件。一个我的窗户10,我将它放在C:\Users\yourid\Documents\R\R-3.4.3\etc。在Linux中,它会有所不同。
  3. 使用文本编辑器打开 Renviron.site 并粘贴代理。保存文件并重新启动R

     options(Internet.info = 0)
     http_proxy=http://proxy.companydomain:8080/
     https_proxy=https://proxy.companydomain:8080/
    
  4. 在我的情况下,我在设置代理后遇到了另一个错误,即unsupported proxy ....libcurl is built without the HTTPS-proxy support.。因此,我将第二行更改为http://而不是https://。这没有任何错误。

    https_proxy=http://proxy.companydomain:8080/
    

    希望这会有所帮助。设置代理有点容易,让事情自动发生。

答案 2 :(得分:0)

我已经成功地通过这种方式从 Github 手动安装了 R 包:

# 1. Find the location where R saves installed packages:
libpath <- .libPaths()

# 2. On the Github webpage of the package you want to install, 
## in the top right corner click on "Code", 
## then click "Download ZIP", save it, unzip it, 
## and move the unzipped folder to the `libpath` directory identified above,
## ensuring the folder name has retained the correct name

# 3. In R, set the working directory to `libpath`
setwd(libpath[1])

#4. Install and load the package manually using the `install()` function of 
##   the `devtools` package:
library(devtools)
install("tsDyn")
library(tsDyn)