Package unavailable in package build after R update using packrat - r

I recently updated to R 3.1.3 and I am building a package using RStudio and packrat. I am trying to re-build my package using RStudio's in built "Build and Reload" tool, but it won't work. I keep receiving the following error:
Updating standaRd documentation
Loading standaRd
Error in (function (dep_name, dep_ver = NA, dep_compare = NA) :
Dependency package ggplot2 not available.
Calls: suppressPackageStartupMessages ... <Anonymous> -> load_all -> load_depends -> mapply -> <Anonymous>
Execution halted
Exited with status 1.
The thing is, I have ggplot2 installed in all places including my local libraries and my packrat libraries for this project for both R 3.1.2 and R 3.1.3. I have tried loading them in to no avail.
Also, using devtools::build() and devtools::document() both work, so I am assuming that this is an RStudio issue?
I am using RStudio Version 0.99.235. I also cannot see any of my documentation for my package and it doesn't appear to be in my packrat library.
I have since uninstalled R 3.1.3 and reverted back to R 3.1.2 and I am still getting the same issue.
These are my dependencies:
Depends:
R (>= 3.1.2),
ggplot2 (>= 1.0.0),
grid

packrat doesn't seem to be great at handling this, and I always fail to find the documentation I'm looking for. I managed to get it to install packages for the new version, but I don't know exactly which steps were crucial and in which order.
packrat.lock contained a reference to the old RVersion. This can be updated by hand, but packrat::snapshot() also did it for me. I tried packrat::restore() after this and didn't see a new directory for the R version in PROJECT/packrat/lib/ARCH/. I tried restarting and reloading RStudio, the project and packrat a few times and eventually got it to install packages in there. One more project reload and the packages could be seen.
I think there is a "blessed" command sequence for this and it was easier for me in the past.

It may worth to use the renv package instead of packrat.
From https://rstudio.github.io/renv/articles/renv.html
The goal is for renv to be a robust, stable replacement for the
Packrat package, with fewer surprises and better default behaviors.

Related

R studio install package failed

I tried to install the packages in the following way:
pacman::p_load(tidyverse, lubridate, zoo,
timetk, modeltime,
trelliscopejs, seasonal,
tsibble, feasts, fable)
However, I got the below errors:
I'm not sure what's wrong, I'm using the latest R version 4.2.1, the warning seems to suggest that need to change to 4.1.3, is there anyway to install those packages without changing the version?
The problem is not related to the package in itself. The warning about the version only tells you that the last time this package was built was on R 4.1.3, but it should work on R 4.2.
The problem is that the place where R searches this package doesn't exist. If you go here: https://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/, you will see that the last version of R is 3.4, whereas you're looking for a package built in R 4.1 (see the version in the URL address in the error message).
Here's some advice to solve this (I can't reproduce your problem so I can't be sure this works): if you're using RStudio, go to "Tools -> Global Options -> Packages". I think that under "Primary CRAN repository", there should be the name of the current place where R searches for the files to install each package. You can change this: either pick "Global (CDN) - RStudio" or any other that is not too far from your location. Then restart R and try reinstalling the packages.

Error: package or namespace load failed for 'ggplot2': package 'ggplot2' was installed before R 4.0.0: please re-install it Execution halted

I'm really stuck and need some help.
After installing R 4.0.2, I'm getting this error message on R visualizations in Power BI Desktop which were previously working
"Error: package or namespace load failed for 'ggplot2':
package 'ggplot2' was installed before R 4.0.0: please re-install it.
Execution halted"
I already tried to:
reinstall R 4.0.2
reinstall RStudio
reinstall ggplot2
reinstall all packages
reinstall Power BI Desktop. My version is August-2020
Still it does not work.
Considerations:
My visualizations were working well before I installed R 4.0.2
My visualizations are working well on other PCs
When I run the code on RStudio I don't get any error
Any thoughts?
You probably need to go here: https://powerbi.microsoft.com/en-us/support/, but some guesses:
When you did the reinstall, you didn't clean up the old one, so you now have a mix of old and new versions of things. If you can run R code, run
system.file(package="ggplot2")
That's where it is finding the bad version of ggplot2. Get rid of it, and reinstall. If that's not enough, run
.libPaths()
in the broken copy of R. Completely eradicate every directory mentioned there, and reinstall R and all of your contributed packages. (I don't use Power BI, so this might also require you to wipe out some part of it: do so, and reinstall it.)
After all of this, run
packageDescription("ggplot2")
In the last line (or close to it) of what gets printed, you should see something like this:
Built: R 4.0.2; ; 2020-07-16 22:49:23 UTC; unix
If you see that it was built before 4.0.2, then either you missed deleting something, or you (or Microsoft) reinstalled some old version. Then it's probably time to contact that URL above.

Tidyverse not installing

I'm having a bit of a pickle right now with the package tidyverse, that I need for an assignment on layering maps. I tried installing the package using install.packages("tidyverse") and install.packages ("tidyverse", dependencies = TRUE) but when I ran library(tidyverse) it wasn't installed. I searched online and found that I had an older version of RStudio IDE so I uploaded the latest version (1.3.1056).
After installing the newest version, I reinstalled the package but R tells me the following:
"Rtools is required to build R packages but is not currently
installed".
So, I did it, but the R tells me Rtools package is not available for R version 3.5.3.
What can I do to use tidyverse?
It could be a permissions issue, try setting the directory for where you install R packages/libraries on your computer using libpaths. I have to do this on my work laptop because the university has it set up to store things like this in a tempporary directory on the remote server which isn't desirable.
.libPaths("C:/R")
.libPaths()

R Studio 1.1.456 (Windows): Why do I sometimes have to install binary packages instead of installing from the source?

I am asking this question because I recently solved a problem installing R Shiny (see below). However, the answers I find don't expand in detail about why this problem occurs and I really want to understand to improve my knowledge of R and why these things happen.
So my attempt to install Shiny in RStudio failed and I believe these are the important error messages:
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'httpuv' 1.3.3 is being loaded, but >= 1.4.3 is required
ERROR: lazy loading failed for package 'shiny'
* removing 'C:/Program Files/R/R-3.2.2/library/shiny'
* restoring previous 'C:/Program Files/R/R-3.2.2/library/shiny'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-32~1.2/bin/x64/R" CMD INSTALL -l "C:\Program Files\R\R-3.2.2\library" C:\Users\Sam\AppData\Local\Temp\RtmpuI3XHe/downloaded_packages/shiny_1.1.0.tar.gz' had status 1
Warning in install.packages :
installation of package ‘shiny’ had non-zero exit status
I went through the usual processes first to find a solution.
Checked my RStudio was up to date
Checked for and installed package updates
Among the further solutions I tried were:
Downloading the package directly from the R Studio interface
Using devtools to install Shiny from Github
Using install.packages("shiny", dependencies=TRUE).
None of these solutions worked and I believe it is to do with the dependency httpuv, but I'm not sure why.
So in the end the code I was able to use is: install.packages('shiny', type = "binary") and this allowed me to begin using Shiny.
While it wasn't too difficult for me to find a work around for this problem, I would really appreciate someone taking some time out of their day to explain why my version of RStudio in Windows (Version 1.1.456) doesn't support the source package of Shiny and why installing the binary package works. I hate fixing an issue but having zero understanding of it.
R version 3.2.2
Thank you.
Binary versus Source Code Options and Issue
You are experiencing the push-pull friction between the old and new code and R environment dependencies. The reality here is you have to choose between stability and progress. It is difficult to have both.
Consider:
You are running R version 3.2.2 in binary form, that R version was released on August 15th 2015. Yet, you are trying to install the latest source code version of Shiny.
There is a 3-year delta between the package source code version and R version you are using. The package code and R environment source code have evolved.
A lot of changes have occurred between then and now in the compile and source code environment.
Think of it this way.
The binary package image is a snapshot of the compile and source code environment assumptions at the time of compilation. If you download the current source code image you are using a snapshot of the current code environment (Now) which includes literally thousands of small incremental changes to the assumptions and dependencies in the source code files and compile environment. if you look in the shiny package description you note:
Shiny depends on httpuv which depends on Rcpp
httpuv is built on top of the libuv and http-parser C libraries.
To get httpuv to compile from source you'll need to match the R Environment, the dependent libraries and source dependencies manually. No small feat.
Case in point to compile the above packages from source code (github) you'll likely be using Devtools which if you download in binary form was compiled under R version 3.2.5.
The changes, assumptions and inter-dependencies make for a complex backport compile situation. Hence, the advantage of binary package snapshots.
Options:
In this situation, you generally have two options. You can either:
Download a source version that is old that matches your R version and environment.
The downside of this approach is you cannot access current package features.
The upside is that the package and R environment match historical context.
Upgrade to a current R environment
The downside of this approach is you have to roll with the R releases.
The upside is that you get to gain access to the latest package features made available in the current source code.
Solution Options:
How to do the above? In the first case, you might use devtools::install_git and pull the source for a particular branch or version of a package and compile it. In the second, you can upgrade your environment, and then pull and upgrade your packages.
If you want to work off a particular R environment version you have to use the binary versions. Why? These will match the R environment version coding environment assumptions.
This is a classic problem highlighting the push-pull between current code and old code. You have to choose between stability and progress. It is difficult to have both.
I hope the above helps explain the situation.

R 3.0.1 package build warning

I'm building R packages in R 3.0.1 on a Windows machine, using Rtools30 and the 'Build' tools associated with RStudio, which I assume is tied in with devtools (which is up-to-date). My typical process to build a package is:
Load All
Reoxygenize
Build & Reload
Check
Build Source Package
If everything goes without errors or warnings, I then:
install.packages("foo.tar.gz", repos=NULL, type="source")
Since upgrading to R 3.0.1, I now get this warning:
Warning in install.packages :
foo.tar.gz is not available (for R version 3.0.1)
I also tried before installing, and it did not get rid of the warning:
options(install.packages.check.source = FALSE)
Also, I notice this warning when I open the devtools library:
WARNING: Rtools 3.0 found on the path at c:/Rtools is not compatible with R 3.0.1.
Which is weird, Rtools 3.0 is suppose to be good from R >2.15.1 to R 3.0.x
Any ideas what is going on?
This is RStudio specific, as they wrap and/or changed a lot of functions from the utils for better integration. The problem lies with a call to getDependencies() to check for dependencies. But that function will also check whether the original package exists on CRAN and throws the given warning when it doesn't. A package you just built on your own computer is obviously not on CRAN, hence the warning.
In the source of the native install.packages(), getDependencies() isn't called in case you build from source or install from a different repository respectively. RStudio on the other hand calls getDependencies() before it passes everything on to the native install.packages() function.
This has to my knowledge no further effects, apart from confusing people. I didn't find a way to conveniently get rid of this in RStudio, as suppressWarnings() doesn't work in this context due to the complex way RStudio deals with this.
In a basic R console, you shouldn't have any problem.
So for the time being, I'd just ignore this and hope the RStudio team finds time to take care of this minor glitch.

Resources