简体   繁体   English

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

[英]how to install a R package from github manually or offline

I try to download the tsdyn package from github (it is not yet updated on cran) but my proxy prevents me to connect to github.我尝试从 github 下载 tsdyn 包(它还没有在 cran 上更新)但我的代理阻止我连接到 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

Then I downloaded the .zip and tried to install package from .zip and got this error :然后我下载了 .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' 

I don't understand since I can find the DESCRIPTION file in the repository.我不明白,因为我可以在存储库中找到描述文件。 I Think it is trying to connect to internet which is not allowed by my professional connexion.我认为它正在尝试连接到我的专业连接不允许的互联网。 I found that some people with Linux succeeded to have it downloaded by another port than 443 (port 8000 must be allowed I think but not sure) but I have windows 7. I have administrator credentials and it doesn't work either when I try to use R as an administrator.我发现一些使用 Linux 的人成功地通过 443 以外的其他端口下载了它(我认为必须允许端口 8000,但我不确定)但我有 Windows 7。我有管理员凭据,当我尝试时它也不起作用以管理员身份使用 R。 I really don't know anything about proxy configuration so if you have any idea, please try to be the more specific possible about the actions I should do.我真的对代理配置一无所知,因此如果您有任何想法,请尝试更具体地了解我应该执行的操作。

Thanks a lot by advance !非常感谢提前!

Edit1 : I tried your proposal, and remove the unnecessary level in the file repository, I made a Edit1:我尝试了你的建议,并删除了文件存储库中不必要的级别,我做了一个

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

and I got from the terminal "Installing package into 'C:/Users/stephanie/Documents/R/win-library/3.1' (as 'lib' is unspecified). It seemed to work but when I use the command library(tsDyn) in RI got "Erreur dans library(tsDyn), 'tsDyn' n'est pas un nom correct de package installé" (is not a proper name of installed package in english I guess). Though, the files exist in win-library but I noticed that the files MD5 and INDEX which are always present in the other package directories are not present here. An idea ?我从终端“将包安装到‘C:/Users/stephanie/Documents/R/win-library/3.1’(因为‘lib’未指定)。它似乎有效,但是当我使用命令库(tsDyn ) 在 RI 中得到了“Erreur dans library(tsDyn), 'tsDyn' n'est pas un nom correct de package installé”(我猜这不是已安装软件包的正确名称,我猜)。虽然,这些文件存在于 win-library 中但我注意到其他包目录中始终存在的文件 MD5 和 INDEX 在这里不存在。一个想法?

Edit2 : I found a solution, removing as advised the unnecessary level, I used next the install function of devtools and it worked (offline)... Edit2 :我找到了一个解决方案,按照建议删除了不必要的级别,我接下来使用了 devtools 的安装功能并且它工作(离线)......

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

I really don't understand the difference with the terminal command so, if somebody can give me clue, I have solved my pb but I would be interested in understanding how !我真的不明白终端命令的区别,所以,如果有人能给我线索,我已经解决了我的 pb 但我有兴趣了解如何!

You can avoid this by setting up proxy when working behind the firewall.您可以通过在防火墙后面工作时设置代理来避免这种情况。 The instructions to setup proxy from Rstudio are in this Link .从 Rstudio 设置代理的说明在此链接中

  1. Check with your IT admin which proxy you should use to access anything HTTP/HTTPS while on the internal network?请咨询您的 IT 管理员,您应该使用哪个代理来访问内部网络上的任何 HTTP/HTTPS? In most cases, it would be HTTP - http://proxy.companydomain:8080 HTTPS - https://proxy.companydomain:8080在大多数情况下,它将是 HTTP - http://proxy.companydomain:8080 HTTPS - https://proxy.companydomain:8080
  2. Locate the Renviron.site file.找到Renviron.site文件。 One my windows 10, I located it in C:\\Users\\yourid\\Documents\\R\\R-3.4.3\\etc .在我的 Windows 10 中,我将它定位在C:\\Users\\yourid\\Documents\\R\\R-3.4.3\\etc In Linux it varies.在 Linux 中它会有所不同。
  3. Open the Renviron.site using a text editor and paste your proxy.使用文本编辑器打开Renviron.site并粘贴您的代理。 save the file and restart R保存文件并重新启动 R

     options(Internet.info = 0) http_proxy=http://proxy.companydomain:8080/ https_proxy=https://proxy.companydomain:8080/
  4. In my case, I had another error after setting up the proxy, which is unsupported proxy ....libcurl is built without the HTTPS-proxy support.就我而言,我在设置代理后遇到了另一个错误,这是unsupported proxy ....libcurl is built without the HTTPS-proxy support. . . Hence, I changed the second line to http:// instead of https:// .因此,我将第二行更改为http://而不是https:// This worked without any errors.这没有任何错误。

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

    Hope this helps.希望这可以帮助。 It is a bit easy to setup proxy, and let things go automatically.设置代理有点容易,让事情自动进行。

Either move everything up one level so you don't have an intermediary folder called tsDyn and can then:要么将所有内容都上移一层,这样您就没有名为tsDyn的中间文件夹,然后可以:

install_github("MatthieuStigler/tsDyn")

Or leave things as they are and或者让事情保持原样

install_github("MatthieuStigler/tsDyn/tsDyn")

The proof is in the pudding证据就在布丁里

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>

I've had success manually installing R packages from Github this way:我已经成功地通过这种方式从 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM