ViSa
ViSa

Reputation: 2247

Unable to install tidyverse package for r kernel in jupyter

I have recently installed Anaconda and also enabled r kernel by using conda install -c r r-irkernel which i took reference from: https://kyleake.medium.com/how-to-install-r-in-jupyter-with-irkernel-in-3-steps-917519326e41 .

Now from jupyter notebook when I try to install tidyverse package I get this error regarding jsonlite:

Warning message:
"package 'tidyverse' was built under R version 3.6.3"
Error: package or namespace load failed for 'tidyverse' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 namespace 'jsonlite' 1.6 is already loaded, but >= 1.7.2 is required
Traceback:

1. library("tidyverse")
2. tryCatch({
 .     attr(package, "LibPath") <- which.lib.loc
 .     ns <- loadNamespace(package, lib.loc)
 .     env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)
 . }, error = function(e) {
 .     P <- if (!is.null(cc <- conditionCall(e))) 
 .         paste(" in", deparse(cc)[1L])
 .     else ""
 .     msg <- gettextf("package or namespace load failed for %s%s:\n %s", 
 .         sQuote(package), P, conditionMessage(e))
 .     if (logical.return) 
 .         message(paste("Error:", msg), domain = NA)
 .     else stop(msg, call. = FALSE, domain = NA)
 . })
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. value[[3L]](cond)
6. stop(msg, call. = FALSE, domain = NA)

seems like jsonlite' 1.6 is already loaded, but >= 1.7.2 is required is the problem, so when I try to manually install jsonlite then I get this issue:

install.packages("jsonlite")


package 'jsonlite' successfully unpacked and MD5 sums checked
Warning message:
"cannot remove prior installation of package 'jsonlite'"Warning message in file.copy(savedcopy, lib, recursive = TRUE):
"problem copying C:\ProgramData\Anaconda3\Lib\R\library\00LOCK\jsonlite\libs\x64\jsonlite.dll to C:\ProgramData\Anaconda3\Lib\R\library\jsonlite\libs\x64\jsonlite.dll: Permission denied"Warning message:
"restored 'jsonlite'"

The downloaded binary packages are in
    C:\Users\viny\AppData\Local\Temp\RtmpADyCWE\downloaded_packages

so how can i install tidyverse package in jupyter notebook?

Upvotes: 0

Views: 4220

Answers (2)

Noah
Noah

Reputation: 11

I had a similar error when trying to load tidyverse in Jupyter Notebook, but the other answer here did not work for me. The following site helped me:

https://jonathansoma.com/everything/r/r-no-package-called-library/#:~:text=The%20problem,-For%20example%2C%20you&text=This%20might%20be%20happening%20because,to%20install%20the%20tidyverse%20package

Jonathan's site mentions that the error can occur when you have multiple versions or R installed on your computer. If the the R kernel that Python uses differs from the one that R uses, that can cause an error. Running the following code in R Studio and then restarting Jupyter notebook fixed my issue:

install.packages('IRkernel', repos = 'http://cran.us.r-project.org')
IRkernel::installspec()

Upvotes: 1

krassowski
krassowski

Reputation: 15439

Do not mix conda install and install.packages. Only use install.packages if the package is not on conda. tidyverse is on conda (see anaconda.org/r/r-tidyverse), so you should now remove.packages("tidyverse") and then conda install -c r r-tidyverse.

You may be also interested in learning about conda-forge channel which provides much more R packages.

If you are also using Python, this also apply to mixing pip install and conda install - doing so will break your installations in the ways that are difficult to imagine (see Is that a bad idea to use conda and pip install on the same environment?). Largely this can be attributed to conda using its own mechanisms for handling library/package paths which and not interacting great with other distribution systems.

Upvotes: 1

Related Questions