Installation of lavaan and semPlot packages in R at Linux

Installing lavaan R package in Linux has some prerequisites. My experience in Linux Mint 18.1 is that the following code does the job.

In a Linux terminal do:


 sudo apt-get install xorg-dev libjpeg-dev zlib1g-dev gcc g++ build-essential liblapack-dev libtiff5 libtiff-dev liblapack-dev liblapack3 libopenblas-base libopenblas-dev gfortran 


Then, in R install the Matrix package:

 install.packages("Matrix")  

and (normally) without any problem:

 install.packages("lavaan")  

An alternative option is

install.packages("lavaan", dependencies=TRUE, repos='http://cran.rstudio.com/')

Further, since the package "semPlot" is a natural friend to "lavaan" it seems natural to additionally install a couple of packages with the command (in a linux terminal)
 sudo apt-get install libxml2-dev r-cran-xml libcurl4-openssl-dev
and at R environment
 install.packages(c('MatrixModels', 'quantreg', 'car'))

Notice for Linux Mint users

Probably it is a good idea to add to /etc/apt/sources.list
(to a terminal
sudo nano  /etc/apt/sources.list
)
execute the line
deb https://<my.favorite.cran.mirror>/bin/linux/ubuntu xenial/
for example:
deb https://ftp.cc.uoc.gr/mirrors/CRAN//bin/linux/ubuntu xenial/
Source: https://cran.r-project.org/bin/linux/ubuntu/README.html

Then, do not forget to add the corresponding key. In a terminal type

gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
and
gpg -a --export E084DAB9 | sudo apt-key add -
Source: https://askubuntu.com/questions/610449/w-gpg-error-the-following-signatures-couldnt-be-verified-because-the-public-k


In case an error message of the form

ERROR: failed to lock directory ‘R/x86_64-pc-linux-gnu-library/3.2’ for modifyingTry removing ‘/home/epdiamantopoulos/R/x86_64-pc-linux-gnu-library/3.2/00LOCK-nloptr’

when installing semPlot then probably you should remove the folder with rm -rf command, that is:

sudo rm -rf /home/epdiamantopoulos/R/x86_64-pc-linux-gnu-library/3.2/00LOCK-nloptr

and retry with

install.packages("OpenMx", dependencies=TRUE, INSTALL_opts = c('--no-lock'))

and then

install.packages("semPlot", dependencies=TRUE, INSTALL_opts = c('--no-lock'))

source: https://stackoverflow.com/questions/14382209/r-install-packages-returns-failed-to-create-lock-directory

Enjoy!



Comments

Post a Comment