How to avoid Error in load Namespace using R - r

Am trying to launch a shiny app using the below command.
Rscript -e "shiny::runApp('test-app', launch.browser=TRUE)"
However, I get an error as shown below
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'htmltools' 0.4.0 is being loaded, but >= 0.4.0.9003 is required
Calls: :: ... getNamespace -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
I did check my library folder and see that htmltools package is present.
I also tried the below dependencies=TRUE
install.packages(pkgs,lib = "C:/Users/User/Desktop/data/library",repo = "https://cloud.r-project.org",dependencies=TRUE)
Here pkgs is a list containing list of packages that has to be installed.
The problem is same script works in my system but it doesn't work in my colleague's system. How can I resolve this?
Can help me understand what's the issue?

Although Kouadio has the correct answer, I found it difficult to follow those brief instructions, so I'm making them more detailed here.
Quit RStudio.
Find the RStudio launch icon, either on your desktop or in your Windows Start Menu.
Right-click the icon and choose "Run as administrator." Say yes when prompted that this is really what you want to do.
In RStudio, go to the Tools menu and choose Check for Updates.
Select all the packages and choose to update them. Say yes to the relevant prompts.
You should then be able to use the Knit button again, but you probably want to quit RStudio and restart in non-administrative mode before doing so.

I found new solution ,
you need to run rstudio with admin mode for check you update
After all packages are installed
Close Rstudio
Run Rstudio in normal mode .

Related

R Shiny - Error: there is no package called ‘shinyjs’

My app works perfectly when I run it locally, but when I host it in shinyapps.io this error comes out:
An error has occurred
The application failed to start.
Error in value[3L] : there is no package called ‘shinyjs’
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Anonymous
I have two more apps online with the same ui.R and server.R layouts and both work fine. Even if I avoid the code involving shinyjs, it shows the app in the browser but the same error appears in the app log with the package openxlsx. The other two almost-identical apps working perfect got me completely lost.
In my experience, the issue happens in RStudio projects with a DESCRIPTION file, when the offending package (e.g. shinyjs) is NOT included in the Imports section of the DESCRIPTION file.
I know this answer is late but in case is useful, here it is:
1.- Open a terminal and run: sudo R
2.- I installed shinyjs: install.packages("shinyjs", dependencies=TRUE)
3.- Create shinyjs directory: mkdir /usr/local/lib/R/site-library/shinyjs
4.- cd /usr/local/lib/R/site-library/shinyjs
4.- copy the shinyjs folder from the active username home R directory:
cp /home/username/R/x86_64-pc-linux-gnu-library/3.5/shinyjs/* -r .
Go to your web browsers and it will open your app.
Note. Be sure to change username for correct value and remember to set the privileges.
When you deploy your app on shinyapps.io the serve has to understand where the packages were installed from. The two most common sources of package installations probably are:
CRAN
Github
Looking at the documentation you see that Github packages must be installed with devtools. I have had the same issue you face because I had packages installed with remotes or pak, simply reinstall the packages locally you need using either install.packages for CRAN versions and devtools for dev versions and re-deploy:
install.packages("openxlsx")
# install.packages("devtools")
devtools::install_github("daattali/shinyjs")

Radiant R not working on shiny server

As per given instruction on the website, I installed the Radiant package on Ubuntu server with the following command.
install.packages("radiant", repos = "https://radiant-rstats.github.io/minicran/")
Then cloned the repo from here and placed it in the /srv/shiny server/ folder of shiny server.
I can run radiant from addins and from within RStuodio, however as soon as I point my browser to ipaddress:3838/inst/app I get the following error in the browser.
An error has occurred
The application failed to start.
The application exited during initialization.
The shiny server log produces the following error:
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace ‘shiny’ 0.14.2 is already loaded, but >= 1.0 is required
Calls: runApp ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
I checked the shiny version, it is indeed the latest version, I'm not able to identify the problem, any help.
Like i mentioned in the comments, often it helps to install the package outside R (from command line). If you have the package locally available you can use R CMD INSTALL shiny_1.0.3.tar.gz. If you dont have it locally available you could download it with e.g wget from https://cran.r-project.org/src/contrib/shiny_1.0.3.tar.gz.
It´s been a while so I wonder if you fixed the issue in any case there are some new versions of the package that might help. I suggest the following:
Follow the most up to date version at http://vnijs.github.io/radiant/
Try installing directly in the R console without going inside Rstudio o Rstudio server.
Hope that helps!
Cheers!

Build & Reload in RStudio on Windows: devtools::document() says devtools not found

When I click "Build & Reload" on the Build tab within RStudio, I get the following error:
==> devtools::document(roclets=c('rd', 'collate', 'namespace'))
Error in loadNamespace(name) : there is no package called 'devtools'
Calls: suppressPackageStartupMessages ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
Exited with status 1.
But when I just enter devtools::document(roclets=c('rd', 'collate', 'namespace')) directly into the console, it works.
In addition, if I uncheck "Build & Reload" under "Automatically roxygenize when running:" in the Build Tools -> Roxygen config, the error disappears.
I've installed the latest devtools with devtools::install_github("hadley/devtools"). I'm using Windows.
If anyone has an suggestions, thank you in advance!
I had to uncheck "Build & Reload" under "Automatically reoxygenize when running:" in the Build Tools -> Roxygen Configure menu. Installing devtools in the program files/r/3.2.3/lib helped, but it still wanted all the dependencies there as well. Using packrat didn't seem to help either..
Here's a convenient solution based on mathematical.coffee's comment:
Just run this from Rstudio:
writeLines("install.packages('devtools', repos = 'https://cran.rstudio.com/')", "inst.R")
system("Rscript --vanilla inst.R")
I encountered this problem multiple times and also with other packages related to devtools (e.g. knitr in the devtools::check()). As it was getting on my nerves, I tried to install devtools in other location of .libPaths(), i.e. in the first standard one (in my case it was /usr/local/lib/R/site-library/). It was telling me that I needed sudo rights. I gave them (as I was utterly annoyed by this) but still, it is needed a large number of dependencies. Therefore, my practical solution was to sudo-copy my "special" R library folder into the standard one. The following code fixed all my problems:
sudo cp -rf /home/myname/R/x86_64-pc-linux-gnu-library/3.4/* /usr/local/lib/R/site-library/
I would like to point out that this is the only effective solution I found. Even so, it lacks elegance and I would definitely prefer if the guys from Rstudio provide a way to link Rstudio to a personally-defined library. It was already my case on startup and I had to add my personal lib to .libPaths() in the file Rprofile.site which is run every time on R startup, but this did not solve the above problem anyhow.
I encounter the same issue, what I solve in the latest version of Rstudio is :
Build -> Configure Build Tools -> Build Tools -> Press Configure Button -> Uncheck "Source
and binary package builds"

Car package not found by R (failed to load)

I am am trying to load a simple dataset using:
library(car)
but I get the following error:
Error in library("car") : there is no package called 'car'
Does anyone have an idea why this happens and how to solve it?
If you don't currently use an IDE (or even if you do), the following will install the package:
install.packages("car")
Before then running
library("car")
You should heed #Iris's advice and use a RStudio if you don't already to manage just this sort of task.
You forgot to install the package before you tried to load it.
Do you use a IDE (integrated development environment)? I can strongly recommmand the use of Rstudio as IDE.
When you installed Rstudio, you can choose in the toolbar: "Tools" > "Install packages..."
Type in "car" and click "install".
As soon as the package is installed, you can load the package with library(car)
I know this post was from several months ago, but I came across it after having the same issue. I followed the instructions here (it's a .doc download).
I typically use R Studio, but was having no luck with this:
install.packages("car")
I opened the R application (not Studio) and followed the instructions on the .doc. I now have the package. Good luck!
For security purposes, I use R in a standard account on a Mac and download packages via a separate admin account. Yesterday I updated Microsoft R Open from 3.2.2 to 3.2.3 and I got this message when I tried to load Rcmdr:
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace ‘nlme’ 3.1-122 is being loaded, but >= 3.1.123 is required
Error: package ‘car’ could not be loaded
I had to log in to my admin account and check for updates. There was one for nlme, that I installed and that allowed car to load.
This worked for me. After downloading the most stable version of R (3.4.4), first, I install.packages("car",dependencies=TRUE) then install all the packages that when loading car I was asked for like haven, foreign, etc. So I installed them separately. Also, I noticed that when I install the packages they go to win-library folder instead of the actual working folder (the packages go to R\win-library\3.4 instead of R\R-3.4.4. So I copied them to the right folder.
I used Tools/Install packages... from R Studio and chose not to compile from source and do this for several packages it complains missing. And it works!

Unable to install ggplot2

I'm having trouble installing ggplot2 into R. I've looked around here and haven't seen the same error that I'm getting.
> install.packages('ggplot2', dep=TRUE)
Warning in install.packages("ggplot2", dep = TRUE) :
'lib = "C:/Program Files/R/R-2.13.1/library"' is not writable
Error in install.packages("ggplot2", dep = TRUE) :
unable to install packages
Can anybody help?
It would actually suffice to invoke as follows:
> install.packages('ggplot2', dep=TRUE, lib=NULL)
and R should substitue lib with the default location, as in my comment.
Or you could change the environment variable itself.
R needs to have write access to your library to install a package there. The other advice you're getting is good and should be preferred, but you can run R (or RStudio) as an administrator (right-click on the .exe and "Run as Administrator" is an option) which should give it write access to your library.
In RStudio:
Try going to "Tools";
At the top you have "Install packages", click on that;
Then click on "Install to Library", change that to another library and save there.

Resources