Can't import a package using library() command - R Studio - r

I was trying to import the package "ggplot2", which I already downloaded, and can't do it through library(ggplot2) command.
It gives me the following error message:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘Rcpp’
Error: package or namespace load failed for ‘ggplot2’
Thanks in advance!

I would run,
install.packages("ggplot2", dependencies = TRUE)
This reinstall ggplot2 and "install uninstalled packages which these packages depend" (from ?install.packages).

Try seeing where your libraries are being downloaded + installed to (not sure what the defaults are on Windows), and then see if R knows where to find them by using the .libPaths() command.
If not, add the directory where they are to your R environment as described in [this post] (RStudio can't find my library on startup) and see whether that helps.
.Library.site <- "\\\\gregorp.homedir.nebula.washington.edu/homes/R/win-library/2.15"
If it helps (but only if it does!) add it to your .Rprofile.

I've finally managed to make gglopt2 work! I just downloaded "Rcpp" and then everything was fine (don't know why it didn't work last time...). Thank you all for your help! ;) Best wishes.

Related

Problem in loading ggplot2 in R version 4.0

I have installed ggplot2 in R but when I try to load it, R gives this ERROR message:
library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): namespace ‘rlang’ 0.4.6 is already loaded, but >= 0.4.7 is required
What should I do?
Thanks in advance.
Install the full tidyverse package, it will load all graphics dependencies include gglot2 and its dependencies too.
install.packages("tidyverse")
As mentioned here:
https://community.rstudio.com/t/i-cant-load-ggplot2-in-my-library-in-r-version-3-4-3/6466
I am working on WINDOWS OS and I had same problems with loading ggplot2 and other libraries. I tried to install it like it was suggested in other threads, but it didn't solve the problem. I found some similar issues in other topics, and i figured out that my Rstudio console wanted to have fresh a toolchain bundle called Rtools. It can be downloaded from CRAN REP.
You have to pick appripiote version for your Rengine version. If you do not know what version of R you have, you have to simple type R.version in console, and then download proper version of Rtools. After that, i updated every libraries in Rstudio. ggplot2, tidyverse and many other are working properly from that time
I hope that it could help somebody :)

Installing missing dependencies in an R package

I'm distributing an R package that requires other packages. If any are missing I get (for example) the following error:
library(whSample)
Error: package or namespace load failed for ‘whSample’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
there is no package called ‘dplyr’
I have code to check and install dependencies in the whSample package, but R fails before it gets to it when it sees the import(dplyr) in NAMESPACE. Here's the first block of code when the package function is called:
is_installed <- function(mypkg) is.element(mypkg, installed.packages()[,1])
whInstall <- function(pkgNames){
for(pkg in pkgNames){
if(!is_installed(pkg)){
install.packages(pkg, repos="http://lib.stat.cmu.edu/R/CRAN")
}
suppressMessages(suppressWarnings(
library(pkg, character.only=T, quietly=T, verbose=F)))
}
}
whInstall(c("magrittr","tools","purrr","openxlsx","data.table","dplyr","glue"))```
How can I get R to do these checks without running afoul of NAMESPACE?
A short answer is that you can ask people to install with
devtools::install_local("your-package.tar.gz")
What's happening behind the scene is that install.packages ignores the dependencies option when installing from a local file. It somehow assumes that the repository from which your are installing the package should also have the dependent packages. But for local files there is no repository, hence no dependency handling occurs.
When you install the package from a local file, install is going to search for dependencies on the same local path... and won't find them.
To get the CRAN dependecies automatically installed, you can use :
install.packages("devtools")
devtools::install_local("MypackageName.zip")

R3.5.0 and data.tables not working

edited 2018-04-26: Changed title as per comments, this is a broader issue with R3.5.0
original:
I'm pretty new to R, and not savvy with all of it's joys.
I've just had my works computer upgrade (result!) to windows 10 with java version 8.1 64bit; r 3.5.0, and r studio 1.1.447.
My code is no longer loving qdap package. It claims to install but won't library in.
CODE:
`pkg <- c("rJava","rmarkdown", "tidyverse","ggplot2", "knitr", "tm", "RColorBrewer", "wordcloud", "qdapDictionaries","qdapRegex", "qdapTools","qdap")
new.pkg <- pkg[!(pkg %in% installed.packages())]
if (length(new.pkg)) {
install.packages(new.pkg, repos = "http://cran.rstudio.com")
}
library(qdap)`
output:
`Loading required package: qdapTools
Error: package or namespace load failed for ‘qdapTools’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘data.table’
Error: package ‘qdapTools’ could not be loaded`
googling suggested I needed to modify the dependencies part, which threw this one
`install.packages(new.pkg, repos = "http://cran.rstudio.com", dependencies = TRUE)
also installing the dependencies ‘data.table’, ‘koRpus’, ‘lda’, ‘proxy’, ‘SnowballC’
Package which is only available in source form, and may need compilation of C/C++/Fortran:
‘data.table’
These will not be installed`
Any thoughts (and fixes!) much appreciated. sorry for obvs noobie question.
I am by no means an expert here, but found a fix for this exact same problem earlier today!
Download and install the most recent version of RTools from the following link:
https://cran.r-project.org/bin/windows/Rtools/.
After restarting R, run this code:
install.packages("data.table")
When the error message arises, you should see a pop-up asking if you'd like to attempt to install the package from its source. Click 'yes' and it should install correctly!
The GitHub for data.table has directions to a daily-build windows binary of data.table https://github.com/Rdatatable/data.table/wiki/Installation
following the instructions on this and installing from the zip file now works. note that a few days ago it did not. Hopefull "normal" install practices will work soon too.

loadNamespace error loading choroplethr package in R [duplicate]

I'm new with R, and I'm having some trouble loading the car library. I use Windows 8.1 (64 bit) and i'm working in 32 bit R environment. I downloaded the library just fine, but when i try to load the car library using library(car) the message i get is:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()),
versionCheck = vI[[j]]) :
there is no package called ‘quantreg’
Error: package or namespace load failed for ‘car’
This message came up asking for several other libraries besides quantreg. I downloaded some of those other libraries in the hope that it would be enough to run car, but it doesn't stop asking for more libraries.
Has anyone had the same issue? This also happened to some people I know, using different operating systems, mostly Windows, but also Linux.
It seems that you did not install the dependencies automatically when you installed car. I'm assuming that you tried installing with Rstudio, which does not automatically install dependencies.
This SO post and this one should help you to install them automatically.
Try reinstalling with the command install.packages("car",dependencies=TRUE).
Additionally, in the future you can check the CRAN page to see the depends, imports, suggests, etc.

Deleted httr, now can't reinstall, or load devtools

I was trying to install twitteR, but the install failed, saying I needed httr >0.6 and I only had 0.3.
I tried to update httr. However, I seemed to have to 2 versions simultaneously, and when I used library(twitteR) it still said I had httr 0.3 and needed 0.6 (sorry I don't have the exact error messages anymore, and can't replicate due to the problems below.)
So, I deleted httr with remove.packages('httr') (this was a mistake).
Now I cannot load devtools
> library(devtools)
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘httr’
Error: package or namespace load failed for ‘devtools’
or install packages
install.packages('httr')
'''Some lines skipped'''
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘httr’
Error: package or namespace load failed for ‘devtools’
Execution halted
I get the same error message as above when trying to install httr from a tarball with R CMD INSTALL.
I'm pretty stuck. Is it time for a clean R install?
And for future reference, how do I update httr?
My best guess -- you have something in your ~/.Rprofile that's attempting to load httr (or a package that uses httr) -- since surely, nothing in base R relies on httr.
I believe install.packages() launches an R sub-process (using the same arguments on load as the current session), which in turn will source that ~/.Rprofile, and cause the errors you are seeing.
If I am correct, one solution would be to move / comment out your ~/.Rprofile and restore it after re-installing httr. Alternatively, launching R with the --vanilla flag (to suppress any site / profile loading) should also help in alleviating the problem.
Running R as R --vanilla fixed the problem.
I could then install httr with
install.packages('httr')
And then loading devtools works and installing twitteR then works as well.

Resources