How to deal with: Error: could not find function "read_csv" - r

I installed the package readr and tried to upload a .csv file in Rstudio.
When I try to load this package I get the following error:
> library(readr)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()),
versionCheck = vI[[j]]) : there is no package called ‘hms’ In addition:
Warning message: Paket ‘readr’ wurde unter R Version 3.2.5 erstellt
Error: Laden von Paket oder Namensraum für ‘readr’ fehlgeschlagen
When I try to upload the .csv file in R I get the error:
> dataX<-read_csv("file.csv")
Error: could not find function "read_csv"
The result of sessionInfo() is:
> sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] colorspace_1.3-2 scales_0.4.1 R6_2.2.2 lazyeval_0.2.0 plyr_1.8.4
[6] tools_3.2.2 gtable_0.2.0 tibble_1.3.0 Rcpp_0.12.10 ggplot2_2.2.1
[11] grid_3.2.2 munsell_0.4.3
I will appreciate your help. Thanks.

Ok, I was able to duplicate the problem on Windows. How and Why?
Resolution - Install R3.4.4
How
Install R3.4.4
Install Rtools3.4.
Launch R
> install.packages("readr")
Why?
The issue here (appears to be) that readr and the TidyVerse packages require later versions of R than R3.2.2. and the WIndows Rtools you have. I was able to duplicate the issue described by installing R3.2.2 and RTools3.2 and then trying to instal readr.
I did not encounter the error on installation of R3.4.4.
Background on Upgrading R on Windows:
You can install multiple versions of R (Base environment) and R Tools (Development environment) on Windows. My personal recommendation is to uninstall R, install the new versions of R, then install the latest R Tools and copy over the libraries per Windows faq below.
R Windows FAQ
2.8 What’s the best way to upgrade?
That’s a matter of taste. For most people the best thing to do is to uninstall R (see the previous Q), install the new version, copy any installed packages to the library folder in the new installation, run update.packages(checkBuilt=TRUE, ask=FALSE) in the new R and then delete anything left of the old installation. Different versions of R are quite deliberately installed in parallel folders so you can keep old versions around if you wish.
For those with a personal library (folder R\win-library\x.y of your home directory, R\win64-library\x.y on 64-bit builds), you will need to update that too when the minor version of R changes (e.g. from 3.0.2 to 3.1.0). A simple way to do so is to copy (say) R\win-library\3.0 to R\win-library\3.1 before running update.packages(checkBuilt=TRUE, ask=FALSE).

I too had the similar problem and re-installing package "tidyverse" did the trick for me while I was already on 3.4.4 version of R.

For me, it was loading tidyverse into the environment that did the trick. Load both tidyverse and dplyr

Related

R - New libraries fail to install even though dependencies are there

I have a rather interesting problem that I cannot find the answer to. I am using a RStudio Server (v. 1.4.1717), and R version 4.1.0 is installed. I try to use Projects with renv and so far it had been quite okay, even though I had problems with occasional library installations.
However, right now I keep getting this error:
Error: package ‘xxx’ required by ‘yyy’ could not be found
I have tried couple of things. I tried changing .libPaths() to a new location, have a fresh installation of each library, but it didn't solve my issue. I also tried doing this inside and outside a project (so, also renv active and disabled) but I keep getting same problem. Just to give an example:
>BiocManager::install("MatrixGenerics", lib = "/media/erkin/lib")
getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for details
replacement repositories:
CRAN: https://packagemanager.rstudio.com/all/__linux__/focal/latest
Bioconductor version 3.14 (BiocManager 1.30.18), R 4.1.0 (2021-05-18)
Installing package(s) 'MatrixGenerics'
trying URL 'https://bioconductor.org/packages/3.14/bioc/src/contrib/MatrixGenerics_1.6.0.tar.gz'
Content type 'application/x-gzip' length 28270 bytes (27 KB)
==================================================
downloaded 27 KB
* installing *source* package ‘MatrixGenerics’ ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error: package ‘matrixStats’ required by ‘MatrixGenerics’ could not be found
Execution halted
ERROR: lazy loading failed for package ‘MatrixGenerics’
* removing ‘/media/erkin/lib/MatrixGenerics’
The downloaded source packages are in
‘/tmp/RtmpgabWCB/downloaded_packages’
Warning message:
In install.packages(...) :
installation of package ‘MatrixGenerics’ had non-zero exit status
I have matrixStats installed, and I can call it. If I check sessionInfo():
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS
Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] matrixStats_0.62.0 BiocGenerics_0.40.0
loaded via a namespace (and not attached):
[1] BiocManager_1.30.18 compiler_4.1.0 tools_4.1.0
This is not the only package this happens with. Many of the other packages I tried to install (e.g. S4Vectors installation cannot find BiocGenerics, BiocStyle installation says no package called BiocManager) just keeps failing.
I am probably missing something, does anybody have an idea why I my R fails to find the installed packages to install new packages?
I solved the issue by removing .Rprofile.
If you have an .Rprofile file and you set the library there, using renv "confuses" the main library path. I think it ends up checking the path .Rprofile shows, even though all the other commands (.libPaths(), find.package()) show renv library path. Removing the .Rprofile removed all the issues for me.

Library installation issues- rlang

I have a new laptop that was working with R and R studio and then after updating packages I have run into continual issues loading or installing R packages in R studio.
I have tried to uninstall R and R studio deleted all folders associated and then re-installed.
removing and re-installing rlang however it keeps coming up as not properly installed.
Checked my .libPath ()
My question is how do you make sure you have closed everything so you do not have any .dll file open and then therefore so that the installer can overwrite .dll? will this solve my issue?
Restarting R session...
> .libPaths()
[1] "C:/R-4.0.4/library"
> install.packages("rlang")
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/rlang_0.4.10.zip'
Content type 'application/zip' length 1181510 bytes (1.1 MB)
downloaded 1.1 MB
package ‘rlang’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\dhiam\AppData\Local\Temp\RtmpuiHNNP\downloaded_packages
> tools::checkMD5sums("rlang")
[1] TRUE
> library(rlang)
Error: package or namespace load failed for ‘rlang’:
.onLoad failed in loadNamespace() for 'rlang', details:
call: NULL
error: The rlang package is not properly installed.
The DLL version does not correspond to the package version.
Please update rlang to the latest version.
Updating packages on Windows requires precautions:
<https://github.com/jennybc/what-they-forgot/issues/62>
> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_xx.1252 LC_CTYPE=English_xx.1252 LC_MONETARY=English_xx.1252
[4] LC_NUMERIC=C LC_TIME=English_xx.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.4 tools_4.0.4 gtable_0.3.0 grid_4.0.4
Please also note, I do not have admin rights to this computer (as it is work laptop).

Install "gradethis" package for code checking in "learnr"

I am creating the interactive tutorials for R for presentation using "learnr" package. For code checking, I need the package "gradethis". When I try to install this package by
"
remotes::install_github("rstudio-education/gradethis")
"
it gives the error message:
.
.
.
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace ‘learnr’ 0.10.1 is being loaded, but >= 0.10.1.9007 is required
ERROR: lazy loading failed for package ‘gradethis’
─ removing ‘/private/var/folders/r2/3nmkgqc51q54tmhxl00tsk2908fpk9/T/RtmpaPONJB/Rinst15003850258d/gradethis’
-----------------------------------
ERROR: package installation failed
Error: Failed to install 'gradethis' from GitHub:
.
.
.
The error message shows "‘learnr’ 0.10.1 is being loaded, but >= 0.10.1.9007 is required", however on CRAN, 0.10.1 is the latest version:
https://cran.r-project.org/web/packages/learnr/index.html
Can anyone help for this case? Many thanks.
The following show sessionInfo()
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.1 rjson_0.2.20 plyr_1.8.6
[4] markdown_1.1 htmltools_0.5.1.9000 tools_3.5.1
[7] base64enc_0.1-3 yaml_2.2.1 Rcpp_1.0.6
[10] rmarkdown_2.6 knitr_1.31 xfun_0.20
[13] digest_0.6.27 tutorial_0.4.3 rlang_0.4.10.9000
[16] evaluate_0.14
Since gradethis is still in a developmental/experimental phase, it is currently only available through GitHub at rstudio/gradethis. gradethis currently requires the developmental version of learnr which is also not yet on CRAN.
Installing both packages from their GitHub repositories will likely resolve your issues:
# install.packages("remotes") # require {remotes}
remotes::install_github("rstudio/learnr")
remotes::install_github("rstudio/gradethis")
Edit: The gradethis repository is now hosted under the rstudio GitHub organization.
Reproduced the error (macOS Big Sur 11.1 / Rstudio 1.3.1093 / R version 4.0.3) and solved the issue by uninstalling learnr with remove.packages("learnr") then installing gradethis with dependencies (including the required version of learnr) using remotes::install_github("rstudio-education/gradethis").
If you get a warning that "Skipping install of 'gradethis' from a github remote, the SHA1 has not changed since last install", use the command remotes::install_github("rstudio-education/gradethis", force = TRUE)
Successfully installing the packages requires the ability to compile from source (instructions for macOS Big Sur: https://stackoverflow.com/a/65334247/12957340)

Error installing packages in RStudio: error reading from connection

I have recently updated both R (version 3.4.1) and RStudio (version 1.0.143) and I am now unable to install packages from Rstudio.
If I install a package in R directly using install.packages() it works fine.
If I try and install a package in Rstudio using either install.packages() or using the package install menu I get the error below. I have tried a few different packages, and have uninstalled and reinstalled both R and RStudio.
To get the error:
Run:
install.packages("lme4")
Output:
Installing package into ‘E:/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
also installing the dependencies ‘minqa’, ‘nloptr’, ‘RcppEigen’
Warning in install.packages :
lzma decoding result 10
Error in install.packages : error reading from connection
I am working off my personal computer, below is some of my system info:
Output from options("repos")
$repos
CRAN CRANextra
"https://cran.stat.auckland.ac.nz/" "http://www.stats.ox.ac.uk/pub/RWin"
attr(,"RStudio")
[1] TRUE
Output from sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_New Zealand.1252 LC_CTYPE=English_New Zealand.1252
LC_MONETARY=English_New Zealand.1252
[4] LC_NUMERIC=C LC_TIME=English_New Zealand.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.4.1 tools_3.4.1
This certainly is an issue with your connection:the proxies you are using and repositories configured in your RStudio. I was getting the same error when I was connected to US VPN from India.I disconnected VPN and restarted RStudio and it worked like a charm!
I had the same issue when I tried to install caret.
The best solution is to restart R studio.
Now the install.packages() works fine.
Just restart the R studio it works for me.
I had the same issue after I misspelled a package name when trying to install it. I restarted R Studio and then it worked.
Kindly select appropriate CRAN mirror in R Studio through following option:
Tools>>>Packages>>>CRAN Mirror(Select appropriate CRAN depending on your location).
A simple solution would be to download manually the zip folder of the package and install it with the command :
install.packages('package.zip', lib='destination_directory',repos = NULL)
Package zip : the path to the zip file of the package
Destination_directory: where the packages are installed by default like C:/Users/unknown/Documents/R/win-library/3.3
Hope it helps

R Package Doesn't Install in Jupyter Notebook, But Installs in RStudio and R app

I'm trying to install the package PerformanceAnalytics using the following code in a Jupyter Notebook, which I've used to install many packages successfully, such as ggplot2, with the following code:
install.packages("PerformanceAnalytics", repos='http://cran.r-project.org')
But I read on many other questions that adding dependencies=TRUE would solve the issue. Unfortunately, it did not. I keep getting the following error message.
install.packages("PerformanceAnalytics", repos='http://cran.r-project.org',
dependencies=TRUE)
Warning message in install.packages("PerformanceAnalytics", repos =
"http://cran.r-project.org"): “installation of package ‘PerformanceAnalytics’
had non-zero exit status”Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
The package installs without a problem in the R app and RStudio. Is there something I'm missing that Jupyter requires for this specific package? I'm using macOS 10.12.5. Below is the info when I run sessionInfo().
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin11.4.2 (64-bit)
Running under: macOS Sierra 10.12.5
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] R6_2.2.0 magrittr_1.5 IRdisplay_0.4.4 pbdZMQ_0.2-4
[5] tools_3.3.2 crayon_1.3.2 uuid_0.1-2 stringi_1.1.2
[9] IRkernel_0.7.1 jsonlite_1.1 stringr_1.1.0 digest_0.6.10
[13] repr_0.10 evaluate_0.10
The solution from the question at Is it possible to install bioconductor package 'rain' in R Jupyter notebook? solved my issue as well. I was using Anaconda's version of R. I uninstalled Anaconda and instead installed Jupyter Notebook and IRkernal manually which resolved my issue. See the answer from the above link for full details.

Resources