Why does my script work in RStudio but not when scheduled? - r

I wrote some scripts, which I want to run periodically in the background. They work if I start them manually in RStudio. With scheduled scripts, I get an error, if I have a one, which loads some packages. With lubridate, it works fine. With readr or dplyr I get an error:
Fehler: package or namespace load failed for 'readr' in
loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck =
vI[[j]]): es gibt kein Paket namens 'fansi' Ausf?hrung angehalten
The same script works from scheduler and in RStudio, if I don't load library(readr), without any more modifications. Fansi is installed.
I also saw an error for tzdb. I think, some packages uses some other basic packages (fansi, tzdb) in an incorrect manner.

The problem is, that R uses other library-pathes than RStudio. I saw it, with print(.libPaths()) in scheduler environment and in dektop environment. I didn´t find the place to change the path in R itself. But I choosed one of the library-paths from R in RStudio. Now everything works. Maybe, someone has a better solution.

Related

R tells me I'm missing a dependency package when I'm not?

I have a handful of R scripts that I routinely run every day so all of the necessary packages have been running just fine for months. Yesterday I installed the RInno package and I believe this has somehow affected other packages because my routine scripts no longer run due to the inability to load my normal packages.
When troubleshooting I started with the odbc package. When trying to load it gives me:
Error: package or namespace load failed for ‘odbc’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘Rcpp’
I then ran .libPaths(), checked both of the returned paths, and the Rcpp package existed in both.
I've even tried re-installing both odbc and Rcpp with no luck. Does anyone know what could be going on here?
Update1: While trying to re-install Rcpp did not work, re-installing dplyr did manage to fix the missing rlang issue. So I decided to go download Rcpp directly from https://cran.r-project.org/web/packages/Rcpp/index.html and then paste it manually into both of my library folders. This seems to have fixed the Rcpp issue but I am now met with the following new error when trying to load odbc or run devtools::session_info():
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : object 'vI' not found
Update2: Ultimately I decided to do a restore on my two library folders to a time before I installed RInno and it seems to have worked. I still have no idea what RInno did but I won't be trying that again.

"Rcmdr" error load failed for ‘car’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):

I'm attempting to run 'Rcmdr' in R. I had it fully functional and accidentally exited the program. Now i can not get back in.
I've tried a number of things;
uninstall and reinstalling R
uninstall and reinstalling 'Rcmdr'
I tried manually installing
Trying different 'CRAN's
and all of the suggestions i saw from previous posts. (i.e.(install.packages("car",dependencies=TRUE)
Below is the error I'm receiving.
The downloaded binary packages are in C:\Users\william\AppData\Local\Temp\Rtmpuazyss\downloaded_packages
> library(Rcmdr)
Loading required package: RcmdrMisc
Loading required package: car
Error: package or namespace load failed for ‘car’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘openxlsx’
Error: package ‘car’ could not be loaded
A common cause of errors like this is that you are working on a system where you don't have write permission on the R package library. You install a package (likely openxlsx in this case), and since it can't write to the system library, it creates a private library for you somewhere where you do have write permission.
But then when you start a new session, it doesn't look in that location, so it thinks openxlsx is not installed, and you get an error like the one you saw.
A short term fix is to just re-install the missing package. But then you'll get the same error in the next session if you restart R.
A better fix is to tell R to look in your private library. You can find where it is after re-installing openxlsx by running
.libPaths()
The first entry in the result will probably be your private library, the second entry will be the standard system one. (You could have more than 2, but that's not likely unless you've already asked for more.) To make sure that your private library always shows up, you need to put the line
.libPaths("whatever was in the first entry")
into a file called .Rprofile in your home directory. For example, I see
> .libPaths()
[1] "/Users/me/R/contrib"
[2] "/Library/Frameworks/R.framework/Versions/3.5/Resources/library"
so I should have
.libPaths("/Users/me/R/contrib")
in my .Rprofile. You'll see some other directory there, use it.

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.

Can't install dada2. Used to work fine

I was using dada2 perfectly fine a month ago on 2 computers. But now everytime I want to load the dada2 package it gives me this error message on both computers. I am using windows. I have seen someone post similar questions for other package but none of the solutions works. It's not a Rcpp problem as I have tried that.
I also reinstall R and have tried every method to install dada2 like from a source, from local file, and from the packages tab from R etc., but none of them work. The other packages such as ggplot2 are working fine so it feels like a dada2 specific problem. Can anyone help please?
The dada2 package is unpacked sucessfully. Then when I load it using library("dada2") it gives error message as below:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
Error: package or namespace load failed for ‘dada2’

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