I have a shiny project using packrat. When I create a Rocker-shiny Docker container I put commands in Dockerfile in order to install packrat package and restore library. However, I see that packrat installs packages into system library (/usr/local/lib/R/...) instead private project library. If I enter in bash docker's console and I start a R session into project dir then reads .Rprofile file and packrat is installed and starts packages installation into private library. How I can get this from Dockerfile?
In my Dockerfile:
RUN cd /srv/shiny-server && \ R -e 'install.packages("packrat" , repos="http://cran.us.r-project.org"); packrat::restore()'
Install packages into /usr/local/lib/R... what is wrong.
However, if I enter into docker bash and start a R session into my project dir, it works fine:
docker exec -it test_app bash
cd /srv/shiny-server
R # start R session into project dir
Packrat is not installed in the local library -- attempting to bootstrap an installation...
> Installing packrat into project private library:
- "/srv/shiny-server/packrat/lib/x86_64-pc-linux-gnu/3.5.3"
* installing *source* package ‘packrat’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (packrat)
> Attaching packrat
> Restoring library
Installing plyr (1.8.1) ... OK (built source)
I encountered the same problem and fixed the issue by restoring the packrat packages in my docker-compose file:
docker-compose.yml:
...
command: [sh,-c, "sudo Rscript config/packrat_restore.R"]
...
packrat_restore.R:
packrat::init(
infer.dependencies = FALSE,
enter = TRUE,
restart = FALSE)
packrat::restore()
As this workaround will always delay the startup of my containers in production, I will still try to fix the problem in the Dockerfile itself...
Related
InfrastructureR_0.1.4.tar.gz is a R source package that I created using RStudio in windows and it works fine.
But when I try to use it in docker file with the command
InfrastructureR_0.1.4.tar.gz is located in the same location as Docker file
Docker is running on ubuntu 18.x machine
RUN R -e "install.packages('InfrastructureR_0.1.4.tar.gz', dependencies=FALSE, verbose=TRUE, repos=NULL, type='source')"
it doesn't install.
I run the docker build by sudo docker build -t myRApp s .
and I get the following error message
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
system (cmd0): /usr/lib/R/bin/R CMD INSTALL
Warning: invalid package ‘InfrastructureR_0.1.4.tar.gz’
Error: ERROR: no packages specified
Warning message:
In install.packages("InfrastructureR_0.1.4.tar.gz", dependencies = FALSE, :
installation of package ‘InfrastructureR_0.1.4.tar.gz’ had non-zero exit status
So how do I install a custom R source package in Docker
It is not enough to have your tar.gz file in the same directory as your Dockerfile. To make a local file available to a Docker container created from an image, you can use the COPY instruction.
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>:
COPY [--chown=<user>:<group>] <src>... <dest>
More in the docker docs:
https://docs.docker.com/engine/reference/builder/#copy
I think the package needs to be copied inside the container so that the container can access it. (or in a location volume that docker has access to)
R running inside the container cannot find the file.
https://www.digitalocean.com/community/tutorials/how-to-share-data-between-the-docker-container-and-the-host
https://docs.docker.com/storage/bind-mounts/
I am trying to get a simple OpenCPU Apps (from https://www.opencpu.org/download.html).
Since I am on Ubuntu on AWS, I follow the instructions for Ubuntu:
# Requires Ubuntu 14.04 (Trusty) or 16.04 (Xenial)
sudo add-apt-repository -y ppa:opencpu/opencpu-1.6
sudo apt-get update
sudo apt-get upgrade
# Installs OpenCPU server
sudo apt-get install -y opencpu
# Done! Open http://yourhost/ocpu in your browser
# Optional: installs rstudio in http://yourhost/rstudio
sudo apt-get install -y rstudio-server
Goes through all right.
Next I try to install the package in Rstudio:
install.packages("opencpu")
Installing package into ‘/home/ruser/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/opencpu_1.6.1.tar.gz'
Content type 'unknown' length 563159 bytes (549 KB)
==================================================
downloaded 549 KB
* installing *source* package ‘opencpu’ ...
** package ‘opencpu’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (opencpu)
The downloaded source packages are in
‘/tmp/RtmpON3Ujv/downloaded_packages’
> library(opencpu)
Initiating OpenCPU server...
Using config: /home/ruser/.opencpu.conf
OpenCPU started.
[httpuv] http://myserver/rstudio/p/1529/ocpu
Error : .onAttach failed in attachNamespace() for 'opencpu', details:
call: rhttpd$init()
error: could not find function "startDynamicHelp"
Error: package or namespace load failed for ‘opencpu’
This is where I get the error. Tried googling the error but no luck.
#gaurav is correct. The instructions on opencpu are very misleading, because it looks like they're showing a single set of instructions, but in fact, the R commands are for running opencpu in an interactive R session, not with your newly installed opencpu cloud server.
To run the sample apps on your new cloud server (which is what I assume you are trying to do), you need to follow the instructions for the cloud server.
Here's the link to the cloud server docs that helped me:
https://cran.r-project.org/web/packages/opencpu/vignettes/opencpu-server.pdf
Specifically, to run the sample apps, you'll need to start an R session as root, and install the packages:
sudo -i
R
#then from r session
library(devtools)
install_github("opencpu/gitstats")
install_github("opencpu/stocks")
#then quit
quit()
exit
then restart the opencpu service:
sudo service opencpu restart
then, you can navigate to the package using the opencpu api. In a web browser, go to:
http://localhost/ocpu/library/gitstats/www/
and voila-
Short question: I want to edit the postgresqlWriteTable function in the RPostgreSQL package and install it on R running on an Ubuntu machine.
Long explanation:
The root of my problem is that I am trying to write to a postgres table with an auto-incrementing primary key column from R using dbWriteTable from RPostgreSQL package.
I read this post: How do I write data from R to PostgreSQL tables with an autoincrementing primary key? which suggested a fix to my problem by changing the function postgresqlWriteTable in the RPostgreSQL package. It works when I interactively use fixInNamespace in OSX environment and edit the function.
Unfortunately I have to run my script on an AWS instance running R on Ubuntu. I have RPostgreSQL installed at this location on my machine: /usr/local/lib/R/site-library/RPostgreSQL . I installed it by invoking R CMD install RPostgreSQL_0.4-1.tar.gz
Now I am trying to find the function postgresqlWriteTable. It is supposed to be in the file PostgreSQLSupport.R . I have searched the whole library - there is no such file.
I realized that on my local machine in the OSX Finder , when I unzip the tar.gz package folder, I can see the file PostgreSQLSupport.R where I am supposed to change the function.
So I changed the function. Then I removed the installed RPostgreSQL from my Ubuntu machine and copied the new folder (from my local machine) into my Ubuntu machine and tried to use devtools to install the package as suggested in the post here: Loading an R Package from a Custom directory
here's what happened:
> library("devtools")
> install("/usr/local/lib/R/site-library/RPostgreSQL")
Error: Can't find '/usr/local/lib/R/site-library/RPostgreSQL'.
> install("RPostgreSQL", "/usr/local/lib/R/site-library/RPostgreSQL")
Installing RPostgreSQL
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet \
CMD INSTALL '/datasci/nikhil/RPostgreSQL' \
--library='/usr/local/lib/R/site-library' --install-tests
* installing *source* package ‘RPostgreSQL’ ...
file ‘R/PostgreSQLSupport.R’ has the wrong MD5 checksum
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing ‘/usr/local/lib/R/site-library/RPostgreSQL’
Error: Command failed (1)
I am at my wit's end !
Copy the pacakge .tar.gz file to the AWS machine.
Unpack this file so you have a directory structure.
Edit the function inside the file and save your changes.
You may also have to increase the version number in the DESCRIPTION file.
Use devtools::build to create a new .tar.gz file.
Install this updated version of the package.
I just ran the following command after running R CMD build pkg and R CMD check pkg and it completed without errors.
R CMD install -t /home/wdkrnls/R/x86_64-unknown-linux-gnu-library/3.1 pkg_0.1.0.tar.gz
However, I still can't use it via library(pkg) from R. Looking in the library directory, all I see is the tarball, no pkg directory. When I try and untar it and then load in R, I get the error:
Error in library(e2pa) : 'e2pa' is not a valid installed package
Alternatively, when I try to install with
R CMD install -l /home/wdkrnls/R/x86_64-unknown-linux-gnu-library/3.1 pkg_0.1.0.tar.gz
It tells me -l is an invalid option.
Another failed possibility:
R CMD install -t /home/wdkrnls/R/x86_64-unknown-linux-gnu-library/3.1/pkg pkg_0.1.0.tar.gz
install: accessing `/home/wdkrnls/R/x86_64-unknown-linux-gnu-library/3.1/pkg': No such file or directory
What is the right way to install a package into a personal library in R?
Unix commands are case-sensitive and
R CMD install ....
as you typed invokes a different /usr/bin/install than the R-internal script INSTALL which the actually mandated form
R CMD INSTALL ...
uses. See all the relevant docs -- it is always UPPERCASE.
Once you have the correct script, -l ... is recognised:
edd#max:~$ R CMD INSTALL -l /tmp/demo git/drat_0.0.2.4.tar.gz
* installing *source* package ‘drat’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (drat)
edd#max:~$
I am trying to install the packages rpanel and tkrplot on RStudio. After downloading and installing there I got this message:
downloaded 686 Kb
* installing *source* package ‘rpanel’ ...
** package ‘rpanel’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
Error in structure(.External(.C_dotTcl, ...), class = "tclObj") :
[tcl] can't find package BWidget.
Error : unable to load R code in package ‘rpanel’
ERROR: lazy loading failed for package ‘rpanel’
* removing ‘..../R/i686-pc-linux-gnu-library/3.0/rpanel’
Warning in install.packages :
installation of package ‘rpanel’ had non-zero exit status
The downloaded source packages are in
‘/tmp/Rtmp1MdC0f/downloaded_packages’
I already installed BWidget on my own, but it didn't help.
Anyone any ideas about this problem and maybe can help me?
The system is Ubuntu 12.04.
Under windows 7 there is no problem and everything is working fine.
There are easier ways to install BWidgets. On my mac with Macports I did:
sudo port install BWidget
On Ubuntu you can probably install it with apt-get:
sudo apt-get install bwidget
"Stumbled across this while looking for an answer to the same question. Like an unfortunate number of library authors, the BWidgets people have assumed that the only people who need to use their libraries are planning to code with them. For those of us who've never used TCL, the installation instructions mean nothing.
From the a document called tuto-install-tkabber on the tkabber.jabber.ru website (irritating spam catcher won't let me post a URL), the answer is:
Install the BWidgets directory into the "lib" directory returned by:
whereis tcl
It should look something like: /usr/lib/tcl8.4"
from http://www.linuxquestions.org/questions/linux-software-2/where-to-install-bwidget-tcl-98583/ did the trick for me
Also I got BWidget from: http://sourceforge.net/projects/tcllib/files/BWidget/1.7.0/BWidget-1.7.0.zip/download
#Calimo's answer worked for me on Linux Mint 18.3 RStudio R 3.6.0. I would have commented in #Calimo's thread except for the stupid 50 reputation limit.
sudo apt-get install bwidget
Also works for Ubuntu 18 R 3.4.4 but if you get an X11 issue with rgl then this helped from #Ouistiti.
I had similar issues trying to get biotools working in Rstudio (on Ubuntu 16.04), where rpanel and tkrplot are required. Even after installing Bwidget per Calimo's answer, I got the error installation of package ‘tkrplot’ had non-zero exit status because tk.h: No such file or directory. If you look in the directory, this error is definitely correct. You need to get tk.h in there. I found out how to do so elsewhere on stackexchange:
Install tcl-dev package using apt or synaptic; tcl contains the
runtime, while tcl-devel contains header and development files. Do the
same with tk-dev
from:
https://stackoverflow.com/a/9649478/10405322
Thus,
sudo apt-get install tcl-dev
sudo apt-get install tk-dev
download BWidget from
http://sourceforge.net/project/showfiles.php?group_id=12883
once you get the archive BWidget-1.7.0.tar.gz move it to /usr/local/lib and install it with following code in terminal:
sudo mv /some_download_path/BWidget-1.7.0.tar.gz /usr/local/lib
cd /usr/loca/lib
sudo tar zxf BWidget-1.7.0.tar.gz
ok, done.