Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

Cannot install an R package from Github

I'm trying to run devtools::install_github("gaborcsardi/notifier") but R does not appear to be properly recognizing RTools; which is located in C:Rtools.

After following the instructions on https://github.com/r-lib/devtools/issues/1772, running pkgbuild::find_rtools() still gives me the following error using the CRAN version of devtools and pkgbuild:

Error in rethrow_call(c_processx_exec, command, c(command, args), stdin, : Command not found @win/processx.c:977

Here is my session_info():

- Session info ----------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.2 (2018-12-20)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/Chicago             
 date     2019-09-03                  

- Packages --------------------------------------------------------------------------------------------------------------
 ! package         * version   date       lib source        
   assertthat        0.2.1     2019-03-21 [1] CRAN (R 3.5.3)
   backports         1.1.4     2019-04-10 [1] CRAN (R 3.5.3)
   bindr             0.1.1     2018-03-13 [2] CRAN (R 3.5.2)
   bindrcpp          0.2.2     2018-03-29 [2] CRAN (R 3.5.2)
   bit               1.1-14    2018-05-29 [1] CRAN (R 3.5.2)
   bit64             0.9-7     2017-05-08 [1] CRAN (R 3.5.2)
   blob              1.1.1     2018-03-25 [1] CRAN (R 3.5.3)
   callr             3.3.1     2019-07-18 [1] CRAN (R 3.5.3)
   cellranger        1.1.0     2016-07-27 [2] CRAN (R 3.5.2)
   cli               1.1.0     2019-03-19 [1] CRAN (R 3.5.3)
   crayon            1.3.4     2017-09-16 [1] CRAN (R 3.5.3)
   curl              3.3       2019-01-10 [1] CRAN (R 3.5.3)
   data.table        1.12.2    2019-04-07 [1] CRAN (R 3.5.3)
   DBI               1.0.0     2018-05-02 [1] CRAN (R 3.5.3)
   desc              1.2.0     2018-05-01 [1] CRAN (R 3.5.3)
   devtools        * 2.1.0     2019-07-06 [1] CRAN (R 3.5.3)
   digest            0.6.19    2019-05-20 [1] CRAN (R 3.5.3)
   dplyr           * 0.7.8     2018-11-10 [1] CRAN (R 3.5.2)
   fs                1.3.1     2019-05-06 [1] CRAN (R 3.5.3)
 D glue              1.3.1     2019-03-12 [1] CRAN (R 3.5.3)
   hms               0.4.2     2018-03-10 [1] CRAN (R 3.5.3)
   httr            * 1.4.0     2018-12-11 [2] CRAN (R 3.5.2)
   jsonlite          1.6       2018-12-07 [2] CRAN (R 3.5.2)
   lubridate       * 1.7.4     2018-04-11 [2] CRAN (R 3.5.2)
   magrittr          1.5       2014-11-22 [1] CRAN (R 3.5.3)
   mailR           * 0.4.1     2015-01-14 [1] CRAN (R 3.5.3)
   memoise           1.1.0     2017-04-21 [2] CRAN (R 3.5.2)
   odbc            * 1.1.6     2018-06-09 [1] CRAN (R 3.5.2)
   packrat           0.5.0     2018-11-14 [1] CRAN (R 3.5.3)
   pillar            1.4.1     2019-05-28 [1] CRAN (R 3.5.3)
   pkgbuild        * 1.0.5     2019-08-26 [1] CRAN (R 3.5.3)
   pkgconfig         2.0.2     2018-08-16 [1] CRAN (R 3.5.3)
   pkgload           1.0.2     2018-10-29 [1] CRAN (R 3.5.3)
   plyr              1.8.4     2016-06-08 [2] CRAN (R 3.5.2)
   prettyunits       1.0.2     2015-07-13 [1] CRAN (R 3.5.3)
   processx        * 3.4.1     2019-07-18 [1] CRAN (R 3.5.3)
   ps                1.3.0     2018-12-21 [1] CRAN (R 3.5.3)
   purrr             0.3.2     2019-03-15 [1] CRAN (R 3.5.3)
   R.methodsS3       1.7.1     2016-02-16 [1] CRAN (R 3.5.2)
   R.oo              1.22.0    2018-04-22 [1] CRAN (R 3.5.2)
   R.utils           2.8.0     2019-02-14 [1] CRAN (R 3.5.3)
   R6                2.4.0     2019-02-14 [1] CRAN (R 3.5.3)
   Rcpp              1.0.1     2019-03-17 [1] CRAN (R 3.5.3)
   RDCOMClient     * 0.93-0    2018-04-28 [1] local         
   readxl          * 1.3.1     2019-03-13 [1] CRAN (R 3.5.3)
   rematch           1.0.1     2016-04-21 [2] CRAN (R 3.5.2)
   remotes           2.1.0     2019-06-24 [1] CRAN (R 3.5.3)
   reshape         * 0.8.8     2018-10-23 [1] CRAN (R 3.5.3)
 D rJava             0.9-11    2019-03-29 [1] CRAN (R 3.5.3)
   rlang             0.4.0     2019-06-25 [1] CRAN (R 3.5.3)
   rprojroot         1.3-2     2018-01-03 [2] CRAN (R 3.5.2)
   rstudioapi        0.10      2019-03-19 [1] CRAN (R 3.5.3)
   rvest           * 0.3.4     2019-05-15 [1] CRAN (R 3.5.3)
   sessioninfo       1.1.1     2018-11-05 [1] CRAN (R 3.5.3)
   splitstackshape * 1.4.8     2019-04-21 [1] CRAN (R 3.5.3)
   stringi           1.4.3     2019-03-12 [1] CRAN (R 3.5.3)
   stringr           1.4.0     2019-02-10 [1] CRAN (R 3.5.3)
 D testthat          2.1.1     2019-04-23 [1] CRAN (R 3.5.3)
   tibble            2.1.1     2019-03-16 [1] CRAN (R 3.5.3)
   tidyr           * 0.8.3     2019-03-01 [1] CRAN (R 3.5.3)
   tidyselect        0.2.5     2018-10-11 [1] CRAN (R 3.5.3)
   usethis         * 1.5.0     2019-04-07 [1] CRAN (R 3.5.3)
   withr             2.1.2     2018-03-15 [1] CRAN (R 3.5.3)
   writexl         * 1.1       2018-12-02 [2] CRAN (R 3.5.2)
   XML             * 3.98-1.19 2019-03-06 [1] CRAN (R 3.5.2)
   xml2            * 1.2.0     2018-01-24 [1] CRAN (R 3.5.3)

[1] \termna.local/Shares/User Shares/Kyle.Dixon/Documents/R/win-library/3.5
[2] \termna.local/Shares/User Shares/Kyle.Dixon/Documents/R/R-3.5.2/library

 D -- DLL MD5 mismatch, broken installation.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's not uncommon for utilities (in R or other languages/tools) to be able to deal with simple file paths and schema-based URLs (e.g., https://... or file:///...), I think the number of tools that equally deal with Windows' UNC paths (i.e., \serversharepath) is much less. While I believe that R is doing it just fine for finding the files (otherwise you'd have other problems by having your only two .libPaths() be UNC shares), the underlying tools (including gcc) might not.

I think the way-forward is to install the new package(s) into a directory that is not a network share. I also think this can be a temporary location, where the packages, once installed, can be moved/migrated over to the network share.

Below is a function that simplifies creation of a temporary directory, install to that directory, then move to the network share. (It doesn't actually check if the tgt directory is a network share, the assumption is that you would not need to use this is your first library path is local.)

#' Install a package(s) using a temp-local directory
#'
#' On Windows, if '.libPaths()' starts with a UNC network share,
#' package compilation might not work correctly. This function creates
#' a temporary local directory, executes the desired code in 'expr',
#' and moves any new packages into the normal first library path.
#' 
#' @param expr expression such as 'install.packages("car")' or
#'   'devtools::install_github(...)'; the expression must natively
#'   install into the first of '.libPaths()', but if you try something
#'   like 'install.packages(.., lib="some/other/path"), then the
#'   temporary libpath will not be used (and may fail)
#' @param tgt character, the directory to move the isntalled
#'   package(s)
#' @param cleanup logical, whether to remove the temporary libpath
#' @return nothing
with_local_libpath <- function(expr, tgt = .libPaths()[1], cleanup = TRUE) {
  if (length(tgt) > 1) {
    warning("'tgt' must be length 1")
    tgt <- tgt[[1]]
  }
  if (length(tgt) < 1 || !dir.exists(tgt)) {
    stop("'tgt' must be length 1 and an existing directory")
  }

  dir.create(tmplib <- tempfile(pattern = "local_libpath_"))
  message("Local (temp) libpath: ", sQuote(tmplib))
  oldlib <- .libPaths()
  .libPaths(c(tmplib, oldlib))
  on.exit(.libPaths(oldlib), add = TRUE)

  force(expr)

  newstuff <- list.files(tmplib, full.names = TRUE)
  if (length(newstuff)) {
    newdirs <- file.path(oldlib[1], basename(newstuff))
    message("New packages found: ", paste(sQuote(basename(newstuff)), collapse = ", "))
    message("Moving to: ", sQuote(tgt))
    file.copy(newstuff, tgt, recursive = TRUE)
    if (cleanup) {
      message("Cleaning up")
      unlink(tmplib, recursive = TRUE)
    }
  } else {
    message("No new packages found (?)")
  }
  invisible()
}

I tested this with some simple examples, but not extensively, so caveat emptor. I don't have a network-mounted lib-path, so I'll force one (to a server I maintain):

.libPaths(c("\\myserver/r2evans/R/win.library/3.5", .libPaths()))

Failing installation:

remotes::install_github("gaborcsardi/notifier@d92b1b6")
# Downloading GitHub repo gaborcsardi/notifier@d92b1b6
# v  checking for file 'C:Users
2AppDataLocalTempRtmpWgKbkW
emotes43cc57193c83gaborcsardi-notifier-d92b1b6/DESCRIPTION' (377ms)
# -  preparing 'notifier':
# v  checking DESCRIPTION meta-information
# -  checking for LF line-endings in source and make files and shell scripts
# -  checking for empty or unneeded directories
# -  building 'notifier_1.0.0.tar.gz'
#    
# Installing package into '\myserver/r2evans/R/win.library/3.5'
# (as 'lib' is unspecified)
# * installing *source* package 'notifier' ...
# ** R
# ** inst
# Error in file.create(to[okay]) : 
#   (converted from warning) cannot create file 'myserver/r2evans/R/win.library/3.5/notifier/R.ico', reason 'No such file or directory'
# * removing '\myserver/r2evans/R/win.library/3.5/notifier'
# In R CMD INSTALL
# Error: Failed to install 'notifier' from GitHub:
#   (converted from warning) installation of package 'C:/Users/r2/AppData/Local/Temp/RtmpWgKbkW/file43cc60c05cc/notifier_1.0.0.tar.gz' had non-zero exit status

(I chose a specific version because of https://github.com/gaborcsardi/notifier/issues/22. While the error is different than your error, I suspect that the failure is for a similar/related reason.)

Successful installation:

with_local_libpath(remotes::install_github("gaborcsardi/notifier@d92b1b6"))
# Local (temp) libpath: 'C:Users
2AppDataLocalTempRtmpWgKbkWlocal_libpath_43ccbf98e2'
# Downloading GitHub repo gaborcsardi/notifier@d92b1b6
# v  checking for file 'C:Users
2AppDataLocalTempRtmpWgKbkW
emotes43cc7cb66d1fgaborcsardi-notifier-d92b1b6/DESCRIPTION' (396ms)
# -  preparing 'notifier':
# v  checking DESCRIPTION meta-information
# -  checking for LF line-endings in source and make files and shell scripts
# -  checking for empty or unneeded directories
# -  building 'notifier_1.0.0.tar.gz'
#    
# Installing package into 'C:/Users/r2/AppData/Local/Temp/RtmpWgKbkW/local_libpath_43ccbf98e2'
# (as 'lib' is unspecified)
# * installing *source* package 'notifier' ...
# ** R
# ** inst
# ** byte-compile and prepare package for lazy loading
# ** help
# *** installing help indices
#   converting help for package 'notifier'
#     finding HTML links ... done
#     notify                                  html  
# ** building package indices
# ** testing if installed package can be loaded
# *** arch - i386
# *** arch - x64
# * DONE (notifier)
# In R CMD INSTALL
# New packages found: 'notifier'
# Moving to: '\myserver/r2evans/R/win.library/3.5'
# Cleaning up

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...