How to install R packages in RStudio Server - r

I converted an old laptop of mine into a Ubuntu Server (18.04) which I would like to use for file sharing and running RStudio Server.
I successfully download RStudio Server and can open it on my new laptop through Chrome.
I would like to download tidyverse (or just dplyr and stringr) to run a few commands, but when I do install.packages("dplyr") I get the following message:
Installing package into ‘/home/jacobdavis95/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/dplyr_0.8.3.tar.gz'
Content type 'application/x-gzip' length 1173098 bytes (1.1 MB)
==================================================
downloaded 1.1 MB
* installing *source* package ‘dplyr’ ...
** package ‘dplyr’ successfully unpacked and MD5 sums checked
** libs
Followed by this line, repeated many times
g++ -I/usr/share/R/include -DNDEBUG -I../inst/include -DRCPP_DEFAULT_INCLUDE_CALL=false -DCOMPILING_DPLYR -DRCPP_USING_UTF8_ERROR_STRING -DRCPP_USE_UNWIND_PROTECT -DBOOST_NO_AUTO_PTR -I"/home/jacobdavis95/R/x86_64-pc-linux-gnu-library/3.4/BH/include" -I"/home/jacobdavis95/R/x86_64-pc-linux-gnu-library/3.4/plogr/include" -I"/home/jacobdavis95/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -fpic -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
and finally
/tmp/cc3w1guR.s: Assembler messages:
/tmp/cc3w1guR.s: Fatal error: can't write 3924 bytes to section .debug_loc of mutate.o: 'No space left on device'
/tmp/cc3w1guR.s: Fatal error: can't close mutate.o: No space left on device
/usr/lib/R/etc/Makeconf:168: recipe for target 'mutate.o' failed
make: *** [mutate.o] Error 1
ERROR: compilation failed for package ‘dplyr’
* removing ‘/home/jacobdavis95/R/x86_64-pc-linux-gnu-library/3.4/dplyr’
Warning in install.packages :
installation of package ‘dplyr’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmplNsTeo/downloaded_packages’
I don't understand what some of these messages mean. One of the lines also says, "no space left on device" which doesn't make sense because it's a 500 GB SDD that is nearly empty.
Most forums/websites I've looked at aren't involving Ubuntu Server, just Ubuntu Desktop. I did try following the advice on https://www.r-bloggers.com/installing-rstudio-server-on-ubuntu-server/ but ended up running into the same issues.
Has anyone had this issue before? How do I go about fixing this?

You can use this to use the apt package manager to install dplyr and dependencies instead on any ubuntu (works for me on 18.04 and 19.10):
sudo apt-get install r-cran-dplyr

For whatever reason, there was an issue with the initial installation of Ubuntu Server, and the system was only registering that I had 4 GB on the drive. As a result, I reinstalled Ubuntu Server and it corrected itself, and now there is enough space to install packages.

Related

Error message at installation of Rttf2pt1 version 1.3.8 in R

Iam trying to import windows fonts into R/R.Stuido (both latest versions used with Windows 10). Some time ago I was successful on another Windows 10 device using this code:
install.packages("pkgbuild")
library(extrafont)
library(remotes)
remotes::install_version("Rttf2pt1", version = "1.3.8")
extrafont::font_import()
When I tried to re-run that one on the actual device I am running into troubles with the installation of the respective Rttf2pt1 version. It seems to run into installation problems as the the error message is as follows:
Downloading package from url: https://cran.rstudio.com//src/contrib/Archive/Rttf2pt1/Rttf2pt1_1.3.8.tar.gz
Installing package into ‘C:/Users/.../R/win-library/4.1’
(as ‘lib’ is unspecified)
* installing *source* package 'Rttf2pt1' ...
** package 'Rttf2pt1' successfully unpacked and MD5 sums checked
** using staged installation
** libs
running 'src/Makefile.win' ...
echo "make ttf2pt1 in ttf2pt1/ ..."
make ttf2pt1 in ttf2pt1/ ...
(cd ttf2pt1; /c/PROGRA~1/rtools40/usr/bin/make -f "C:/PROGRA~1/R/R-41~1.1/etc/x64/Makeconf" -f Makefile CC="`"C:/PROGRA~1/R/R-41~1.1/bin/R" CMD config CC`" CFLAGS="`"C:/PROGRA~1/R/R-41~1.1/bin/R" CMD config CFLAGS` -DWINDOWS -Wno-comment -Wno-format -Wno-logical-op-parentheses -Wno-pointer-sign -Wno-unused-function -Wno-unused-variable -Wno-parentheses -Wno-unused-label -Wno-maybe-uninitialized -Wno-unused-but-set-variable -Wno-unused-value" ttf2pt1)
C:/Program Files/rtools40/mingw64/bin/gcc -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -DWINDOWS -Wno-comment -Wno-format -Wno-logical-op-parentheses -Wno-pointer-sign -Wno-unused-function -Wno-unused-variable -Wno-parentheses -Wno-unused-label -Wno-maybe-uninitialized -Wno-unused-but-set-variable -Wno-unused-value -c ttf2pt1.c
make[1]: C:/Program: Command not found
make[1]: *** [Makefile:185: ttf2pt1.o] Error 127
make: *** [Makefile.win:16: all] Error 2
ERROR: compilation failed for package 'Rttf2pt1'
* removing 'C:/Users/.../R/win-library/4.1/Rttf2pt1'
* restoring previous 'C:/Users/.../R/win-library/4.1/Rttf2pt1'
Warning message:
In i.p(...) :
installation of package ‘C:/Users/.../Rttf2pt1’ had non-zero exit status
Any ideas how to solve the problem? Thank you for your help
I could solve it by copy-paste the package from my older PC.
I see that you installed the Rtools on C:/Program Files/.
Try to uninstall the Rtools, then reinstall it to the default installation path, C:/rtools40.
I hope it fixes your problem. It fixed mine.
If the newer version of the Rttf2pt1 package is currently installed on your PC, remove it. Then follow the solution provided in this link to install the older version (1.3.8) from a CRAN repository. In your case, this code will solve it:
url <- "https://cran.r-project.org/src/contrib/Archive/Rttf2pt1/Rttf2pt1_1.3.8.tar.gz"
install.packages(url, repos=NULL, type="source")

Unable to install blotter or quantstrat for R 4.0.2, despite using GitHub Repository

Having a difficult time installing blotter for 4.0.2.
I run the following code:
require(devtools)
install_github("braverock/blotter")
install_github("braverock/quantstrat")
I receive the following error message:
Failed to install 'blotter' from GitHub:
(converted from warning) installation of package ‘/var/folders/7f/fzwn25053j3bp0yd_7swzf540000gn/T//Rtmp5kiwSh/file14db938bb63bf/blotter_0.15.0.tar.gz’ had non-zero exit status
I have successfully installed xts, PerformanceAnalytics, and FinancialInstrument. I also have installed the development tool Clang 8.0 (although I believe it is no longer necessary in R 4.0 and higher).
Any help is appreciated. Thanks in advance.
Edit - Full Output:
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c calcPosAvgCost.c -o calcPosAvgCost.o
calcPosAvgCost.c:31:12: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
if(abs(d_PrevPosQty) > abs(d_PosQty[i])){
^
calcPosAvgCost.c:31:12: note: use function 'fabs' instead
if(abs(d_PrevPosQty) > abs(d_PosQty[i])){
^~~
fabs
calcPosAvgCost.c:31:32: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
if(abs(d_PrevPosQty) > abs(d_PosQty[i])){
^
calcPosAvgCost.c:31:32: note: use function 'fabs' instead
if(abs(d_PrevPosQty) > abs(d_PosQty[i])){
^~~
fabs
2 warnings generated.
clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/usr/local/include -fPIC -Wall -g -O2 -c init.c -o init.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o blotter.so calcPosAvgCost.o init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-blotter/00new/blotter/libs
** R
** data
*** moving datasets to lazyload DB
** demo
** byte-compile and prepare package for lazy loading
Error: (converted from warning) package ‘xts’ was built under R version 4.0.2
Execution halted
ERROR: lazy loading failed for package ‘blotter’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/blotter’
Error: Failed to install 'blotter' from GitHub:
(converted from warning) installation of package ‘/var/folders/7f/fzwn25053j3bp0yd_7swzf540000gn/T//Rtmp5kiwSh/file14db956d7f3bb/blotter_0.15.0.tar.gz’ had non-zero exit status
Ok I found the fix to this issue.
I followed the formula from a previous question regarding quanstrat from #boniface316:
Installing quantstrat via cmd works well for me. Here are the steps:
Create a folder for packages i.e RPackages\
Download the file from github to that specific folder and extract the files to the library name. i.e RPackages\quantstrat\
Go on command line and goto RPackages
Type" R CMD build quantstrat
If it was successful, you will get a message like "building 'package_name_version_number.tar.gz'"
Now type: R CMD INSTALL package_name_version_number.tar.gz
Let me know if you have any other challenges.
This allowed me to install Blotter but not Quantstrat. After playing around with this for awhile, I eventually deleted the Vignettes folder in quanstrat and repeated the steps above. By deleting this folder, I was able to both build and install quantstrat.
After manually installing blotter (check the steps given in the above post), running this command worked for me. This is for the latest R versions (3.6 or 4.0 ).
devtools::install_github("braverock/quantstrat", force = TRUE )
or download the older (for R 3.4 or older) version zip from "https://r-forge.r-project.org/R/?group_id=316"
(note: you might see "Build status: Failed to build", hence download the older version, you can see the option on the page )

Can't install R package: "non-zero exit status" (unless sudo)

Strange behavior: prior to now, I've been able to install R packages using R studio, etc., specifically using install.packages("<package name>"). Now, unless I run R using sudo directly in a terminal window, I can't install packages without receiving the following traceback:
> install.packages("mlbench")
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://mirrors.sorengard.com/cran/src/contrib/mlbench_2.1-1.tar.gz'
Content type 'application/x-gzip' length 920768 bytes (899 KB)
==================================================
downloaded 899 KB
* installing *source* package ‘mlbench’ ...
** package ‘mlbench’ successfully unpacked and MD5 sums checked
** libs
/home/alex/anaconda3/bin/x86_64-conda_cos6-linux-gnu-cc -I/home/alex/anaconda3/lib/R/include -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -I/home/alex/anaconda3/include -fpic -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/home/alex/anaconda3/include -c waveform.c -o waveform.o
make: /home/alex/anaconda3/bin/x86_64-conda_cos6-linux-gnu-cc: Command not found
/home/alex/anaconda3/lib/R/etc/Makeconf:160: recipe for target 'waveform.o' failed
make: *** [waveform.o] Error 127
ERROR: compilation failed for package ‘mlbench’
* removing ‘/home/alex/anaconda3/lib/R/library/mlbench’
* restoring previous ‘/home/alex/anaconda3/lib/R/library/mlbench’
The downloaded source packages are in
‘/tmp/RtmpRBWDWi/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("mlbench") :
installation of package ‘mlbench’ had non-zero exit status
This is happening for quite a few that I have tried, but mlbench is the one that I am most concerned with right now.
Any help is much appreciated.
R (with anaconda)
Kubuntu 17.10 (Artful)
As posted by #r2evans in the comments, this link provides the tip that worked for me.
Because I am using anaconda to manage my R environment, this is what fixed the issue I was having: conda install gxx_linux-64.
Also:
If you are seeing similar errors but with a traceback line similar to make: /home/alex/anaconda3/bin/x86_64-conda_cos6-linux-gnu-gfortran: Command not found..., use a terminal to run the same line as above, but specifying gfortran instead of gcc: conda install gfortran_linux-64.

R package DESCRIPTION - Remotes from Bioconductor should install binary

I am working on an R package (https://github.com/bgbrink/dropClust) and I was testing if it can be installed, since it depends on a number of packages both from CRAN and from Bioconductor. I specified the three dependencies from Bioconductor in the DESCRIPTION:
Remotes:
bioc::flowDensity,
bioc::SamSPECTRAL,
bioc::flowPeaks
However, when I try to install the package, the installation of flowPeaks fails, because the script downloades the source version of the package, which requires GSL to be present in order to be compiled.
* installing *source* package ‘flowPeaks’ ...
** libs
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include `gsl-config --cflags` -fPIC -Wall -g -O2 -c Rpack.cpp -o Rpack.o
/bin/sh: gsl-config: command not found
In file included from Rpack.cpp:16:
./gvector_gmatrix.h:24:10: fatal error: 'gsl/gsl_math.h' file not found
#include <gsl/gsl_math.h>
^
1 error generated.
make: *** [Rpack.o] Error 1
ERROR: compilation failed for package ‘flowPeaks’
When I download the package manually from Bioconductor, everything works fine, because the script downloades the binary version of the package. Can I specify somewhere that this is the default behaviour? I tried options(pkgType = "binary") without success.
Edit: No new ideas, so I'm bumping it once.

Installing nloptr on Linux

I am trying to install the R package nloptr on a CentOS Linux machine that doesn't have internet connection as follows:
install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
This command in turn looks for the following file online
http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz
However, this fails since there is no internet connection to the machine.
I tried the suggestion from the following stackoverflow post:
trouble with Installing nloptr by locally on Ubuntu
I changed the URL in configure and configure.ac files as follows:
NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"
However, I get the following error when I try to install the package again:
> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz", :
installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status
Can someone guide me on how to install this R package locally?
Update 1
Based on the suggestion from Dirk on installing nlopt first, I followed the instructions given in the following page:
http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation
I installed nlopt as follows :
./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
When I tried to re-install nloptr in R, it doesn't look for the nlopt link anymore but throws the following error:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/opt/vertica/R/library/nloptr/libs/nloptr.so':
/opt/vertica/R/library/nloptr/libs/nloptr.so: undefined symbol: nlopt_set_maxtime
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz", :
installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status
Update 2
As suggested by Dirk, I looked into the ldconfig command and used the following reference:
http://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/
I edited the /etc/ld.so.conf file, added the directory /usr/local/lib which contains the shared library and ran the ldconfig command. This added the relevant shared library as shown below:
libnlopt.so.0 (libc6,x86-64) => /usr/local/lib/libnlopt.so.0
libnlopt.so (libc6,x86-64) => /usr/local/lib/libnlopt.so
However, when I tried reinstalling the nloptr package, I still get the same shared object error.
Could someone guide me on the shared library error?
When you say [t]his command in turn looks for the following file online you only get half the story. Together with Jelmer, the maintainer of the actual nloptr package, I modified the package to do the following:
look for an install libnlopt library, and, if found, use it
if not found fall back to the old behaviour and download the library
So you could simply install nlopt via
sudo apt-get install libnlopt-dev
(or the equivalent sudo dpkg -i /media/.... pointing to the file from a
USB drive etc pp) and then reinstall the nloptr package. It will just work. On my machine:
edd#max:~$ install.r nloptr ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB
* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -Wno-unused -pedantic -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)
The downloaded source packages are in
‘/tmp/downloaded_packages’
edd#max:~$
Note how it compiled only two files from the actual R packages having found the nlopt installation.
I had exactly the same problem, on a production machine without direct Internet access, with Red Hat Enterprise Linux Server release 6.6 (Santiago). The fixups proposed above did not work: when installing the nlopt library on the system, the subsequent attempt to install nloptr fail with the "nlopt_set_maxtime" error. I tried to fiddle with compilation options for nlopt, to no avail. I even reproduced the problem on a Ubuntu machine with Internet connection: I uninstalled nloptr, installed nlopt on the system and then the nloptr installation failed.
At last I solved the issue taking the following steps:
Un-install nlopt from the operating system (make sure that it is thoroughly removed).
Manually download nlopt-2.4.2.tar.gz and copy it to /tmp/
Manually download nloptr_1.0.4.tar.gz to a work directory and unpack it; this creates the directory "nloptr/".
Edit "nloptr/configure", comment out the row
$("${R_HOME}/bin/Rscript" --vanilla -e
"download.file(url='${NLOPT_URL}', destfile='${NLOPT_TGZ}')")
and insert a new row:
$("${R_HOME}/bin/Rscript" --vanilla -e
"file.copy(from='/tmp/nlopt-2.4.2.tar.gz', to='${NLOPT_TGZ}')")
Install with "R CMD INSTALL nloptr".
I had a similar problem on Ubuntu. In addition to installing nlopt-dev as Dirk answered, I also had to install pkg-config:
sudo apt-get install pkg-config
Hope this helps.
If you are on CentOS (and have internet access, but the nlopt server is not reachable), you can install nlopt first using
yum install nlopt nlopt-devel
Then you can install nloptr normally.
I had the same issue setting up nloptr on my RHEL 7.2 instance. For those using RHEL you can do the following:
Download & install the following RPMS in the same order:
NLopt-2.4.2-2.el7.x86_64.rpm- https://pkgs.org/centos-7/epel-x86_64/NLopt-2.4.2-2.el7.x86_64.rpm.html
NLopt-devel-2.4.2-2.el7.x86_64.rpm - https://pkgs.org/centos-7/epel-x86_64/NLopt-devel-2.4.2-2.el7.x86_64.rpm.htm
Please note that these RPMs may need additional dependencies to be installed based on your system configuration.
Post this you can install nloptr directly using the install.packages utility or download source from CRAN and install from source as suggested in earlier responses.
Hope this helps!
Kiran
if you are using AWS Linux the below should help
yum --enablerepo=epel install NLopt-devel -y
I just solved this on my server with following two steps:
Install libnlopt-dev and nlopt with
sudo apt-get install libnlopt-dev
pip install nlopt
Use sudo R to launch R and type:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')
I think I have the same problem as you and I am using CentOS 6.5
Remove nlopt and install nloptr with install.packages() in R, a nlopt will be installed automatically.
I removed installed nlopt with the following command in the unzipped nlopt folder.
make uninstall
If you had tried to use epel repository in CentOS and had installed nlopt with yum, try:
yum remove nlopt
After removing existed nlopt, I am able to install nloptr with
install.packages("nloptr")

Resources