Failed packrat::init() leaves broken .Rprofile
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 409
- Forks
- 89
- PR merge metrics
- No merged PRs in 30d
Description
When running packrat::init() on an existing project, it is not uncommon to discover that a package used in the project is not installed locally.
> packrat::init()
Initializing packrat project in directory:
- "~/my_project"
Error: Unable to retrieve package records for the following packages:
- 'Biobase'
In addition: Warning messages:
1: In FUN(X[[i]], ...) :
Package 'Biobase' not available in repository or locally
At this stage, the most natural thing to do is to install the missing package, but the installation will fail because source("packrat/init.R") is now included in the project's .Rprofile even though the packrat/ directory doesn't exist. Furthermore, if there are multiple missing packages, install.packages() doesn't stop on error but tries to download the full package list and then those packages' installations individually fail.
> BiocManager::install("Biobase")
Bioconductor version 3.7 (BiocManager 1.30.1), R 3.5.0 (2018-04-23)
Installing package(s) 'Biobase'
also installing the dependency ‘BiocGenerics’
trying URL 'https://bioconductor.org/packages/3.7/bioc/src/contrib/BiocGenerics_0.26.0.tar.gz'
Content type 'application/x-gzip' length 45638 bytes (44 KB)
==================================================
downloaded 44 KB
trying URL 'https://bioconductor.org/packages/3.7/bioc/src/contrib/Biobase_2.40.0.tar.gz'
Content type 'application/x-gzip' length 1657220 bytes (1.6 MB)
==================================================
downloaded 1.6 MB
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'packrat/init.R': No such file or directory
Execution halted
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
Calls: source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
cannot open file 'packrat/init.R': No such file or directory
Execution halted
... even more output ...
It may be better to condition the sourcing on the existence of packrat/
if (dir.exists("packrat")) source("packrat/init.R")
or to possibly defer updating .Rprofile until init() succeeds, or to restore the old .Rprofile if init() fails.
Edit: I'd be happy to submit a PR for any of the above options if desired.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at packrat::init() and inspect how it updates the project's .Rprofile and creates packrat/init.R. Reproduce the missing-package failure; done means a failed init does not leave .Rprofile sourcing a nonexistent packrat/init.R, and subsequent package installation no longer triggers that error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100