简体   繁体   中英

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.

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 :

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

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 ?

Edit2 : I found a solution, removing as advised the unnecessary level, I used next the install function of devtools and it worked (offline)...

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 !

You can avoid this by setting up proxy when working behind the firewall. The instructions to setup proxy from Rstudio are in this Link .

  1. Check with your IT admin which proxy you should use to access anything HTTP/HTTPS while on the internal network? In most cases, it would be HTTP - http://proxy.companydomain:8080 HTTPS - https://proxy.companydomain:8080
  2. Locate the Renviron.site file. One my windows 10, I located it in C:\\Users\\yourid\\Documents\\R\\R-3.4.3\\etc . In Linux it varies.
  3. Open the Renviron.site using a text editor and paste your proxy. save the file and restart 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. . Hence, I changed the second line to http:// instead of 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:

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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