rstudio / packrat

Packrat is a dependency management system for R
http://rstudio.github.io/packrat/
399 stars 89 forks source link

Invalid Priority field. #381

Open shabbybanks opened 7 years ago

shabbybanks commented 7 years ago

I am getting the error Invalid Priority field for the MASS package when calling packrat::init(). My MWE is as follows:

  1. mkdir -p mytmpdir
  2. cd mytmpdir
  3. echo 'library(car)' >> script.R
  4. R --no-save
  5. require(packrat) && packrat::init()

I get the following:

Installing MASS (7.3-45) ...
Error: Command failed (1)

Failed to run system command:

        '/blahblah/anaconda2/envs/r-3.2.2/lib/R/bin/R' --vanilla CMD INSTALL '/tmp/RtmpOlbwQc/MASS' --library='/blahblah/mytmpdir/packrat/lib/x86_64-pc-linux-gnu/3.2.2' --install-tests --no-docs --no-multiarch --no-demo

The command failed with output:
* installing *source* package 'MASS' ...
** package 'MASS' successfully unpacked and MD5 sums checked
Error : Invalid DESCRIPTION file

Invalid Priority field.
Packages with priorities 'base' or 'recommended' or 'defunct-base' must
already be known to R.

See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.

It seems that my installed.packages() only knows about packages with priority base or NA. This might be due to using R 3.2.2. Note that "just upgrade R" is not a feasible solution for me.

My session info:

library(packrat)
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.7 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] packrat_0.4.8-1 fortunes_1.5-4  drat_0.1.2

loaded via a namespace (and not attached):
[1] tools_3.2.2
kevinushey commented 7 years ago

Strange -- I've never seen this error before; the error seems to imply that your R installation does not believe that MASS is a package of 'Recommended' priority. My understanding is that it has had this priority for quite some time, so I'm surprised this isn't the case on your machine.

What is the output of tools:::.get_standard_package_names() on your system? For example, I see:

> tools:::.get_standard_package_names()
$base
 [1] "base"      "tools"     "utils"     "grDevices" "graphics"  "stats"
 [7] "datasets"  "methods"   "grid"      "splines"   "stats4"    "tcltk"
[13] "compiler"  "parallel"

$recommended
 [1] "MASS"       "lattice"    "Matrix"     "nlme"       "survival"
 [6] "boot"       "cluster"    "codetools"  "foreign"    "KernSmooth"
[11] "rpart"      "class"      "nnet"       "spatial"    "mgcv"

with an R 3.4.0 installation on macOS.

It seems more likely that this is an issue with your R installation than packrat per-se -- are you able to successfully install MASS on your own, with e.g. install.packages("MASS")?

kevinushey commented 7 years ago

Note that the set of standard package names is populated on startup with R code of the form:

## we cannot assume that file.path(R.home("share"), "make", "vars.mk")
## is installed, as it is not on Windows
.get_standard_package_names <-
local({
    lines <- readLines(file.path(R.home("share"), "make", "vars.mk"))
    lines <- grep("^R_PKGS_[[:upper:]]+ *=", lines, value = TRUE)
    out <- strsplit(sub("^R_PKGS_[[:upper:]]+ *= *", "", lines), " +")
    names(out) <-
        tolower(sub("^R_PKGS_([[:upper:]]+) *=.*", "\\1", lines))
    eval(substitute(function() {out}, list(out=out)), envir=NULL)
})

which implies that the file located at file.path(R.home("share"), "make", "vars.mk") might have some unexpected contents. For example, I see:

## Static (i.e., not determined by configure) Make variables to be
## shared *and* grepped from m4/R.m4 and tools/*-recommended.

## There is also 'translations', but that is not Priority: base
## so it can be handled by update.packages() in due course.
R_PKGS_BASE = base tools utils grDevices graphics stats datasets methods grid splines stats4 tcltk compiler parallel
## Those which can be installed initially compiled (not base tools)
R_PKGS_BASE1 = utils grDevices graphics stats datasets methods grid splines stats4 tcltk parallel
## Those with standard R directories (not datasets, methods)
R_PKGS_BASE2 = base tools utils grDevices graphics stats grid splines stats4 tcltk compiler parallel

R_PKGS_RECOMMENDED =  MASS lattice Matrix nlme survival boot cluster codetools foreign KernSmooth rpart class nnet spatial mgcv
# there are dependencies in src/library/Recommended/Makefile*
# which this order respects
shabbybanks commented 7 years ago
> tools:::.get_standard_package_names()
$base
 [1] "base"      "tools"     "utils"     "grDevices" "graphics"  "stats"
 [7] "datasets"  "methods"   "grid"      "splines"   "stats4"    "tcltk"
[13] "compiler"  "parallel"

$recommended
character(0)
shabbybanks commented 7 years ago

OK, thanks for the info, I have

> R.home('share')
"/blahblah/anaconda2/envs/r-3.2.2/lib/R/share"

Then in shell

$ cat /blahblah/anaconda2/envs/r-3.2.2/lib/R/share/make/vars.mk
## Static (i.e., not determined by configure) Make variables to be
## shared *and* grepped from m4/R.m4 and tools/*-recommended.

## There is also 'translations', but that is not Priority: base
## so it can be handled by update.packages() in due course.
R_PKGS_BASE = base tools utils grDevices graphics stats datasets methods grid splines stats4 tcltk compiler parallel
## Those which can be installed initially compiled (not base tools)
R_PKGS_BASE1 = utils grDevices graphics stats datasets methods grid splines stats4 tcltk parallel
## Those with standard R directories (not datasets, methods)
R_PKGS_BASE2 = base tools utils grDevices graphics stats grid splines stats4 tcltk compiler parallel

R_PKGS_RECOMMENDED =
# there are dependencies in src/library/Recommended/Makefile*
# which this order respects

Anaconda to the rescue.

kevinushey commented 7 years ago

My suggestion would be to try patching that file with the recommended packages I noted above, and perhaps reporting this to the Anaconda team.

shabbybanks commented 7 years ago

hahaha, that's a good joke. If I had write access to that file, or much of anything else on this system, I wouldn't be using Anaconda. For now, I think maybe I will just add all of the packages from your R_PKGS_RECOMMENDED to my ignored.package field.

shabbybanks commented 7 years ago

For those stumbling on this issue, my hacky fix suggested above is something like follows:

recommended <- strsplit('MASS lattice Matrix nlme survival boot cluster codetools foreign KernSmooth rpart class nnet spatial mgcv','\\s')[[1]]
packrat::init(options = list(ignored.packages = recommended))
shabbybanks commented 7 years ago

OK, that hacky fix will not fly, I think. After an apparently successful init, I then run status and get some nonsense:

> packrat::status()

The following packages are used in your code, tracked by packrat, but no longer present in your library:
                   from   to
    MASS         7.3-45   NA
    Matrix        1.2-2   NA
    boot         1.3-17   NA
    codetools    0.2-14   NA
    lattice     0.20-33   NA
    mgcv          1.8-9   NA
    nlme        3.1-122   NA
    nnet         7.3-11   NA
    survival     2.38-3   NA

Use packrat::restore() to restore these libraries.

If you then run restore, nothing changes:

> packrat::restore()
Already up to date.
AnonymousRepository commented 6 years ago

Try to run R with sudo. This problem could be related to administrative rights.

shabbybanks commented 6 years ago

If I had sudo rights I sure wouldn't be using Anaconda or R3.2.2.

xyulie commented 5 years ago

Hi, was someone able to fix this issue?

I got the same problem when I try to deploy my shiny-app. I'm running rstudio as admin and still get following errors:

  1. In the browser panel, where the app should launch:

_The application failed to start (exited with code 1).

Error in value[3L] : there is no package called ‘shinythemes’ Ruft auf: local ... tryCatch -> tryCatchList -> tryCatchOne -> Ausführung angehalten_

  1. in the deploy window of rstudio I get following warning:

_Deployment completed: https://juliehofer.shinyapps.io/SOLA_Nachhaltigkeit/ Warnmeldung: In fileDependencies.R(file) : Failed to parse C:/Users/julie/AppData/Local/Temp/Rtmpst12h3/file36603669423e/app.R ; dependencies in this file will not be discovered._

I checked for missing packages with packrat and restored them, the deploy is still not working :(