Articles

Affichage des articles du septembre, 2017

Where are located the packages and who is the owner

I have done a function list.packages() in my package HelpersMG. .libPaths() returns the list of locations for packages... but who is where ?: structure(lapply(.libPaths(), FUN = function(path) {list.dirs(path=path, full.names = FALSE, recursive = FALSE)}), .Names=.libPaths()) To get the owner for each location: structure(as.list(system(paste("ls -ld ", .libPaths()," | awk '{print $3}'", collapse=";"), intern=TRUE)), .Names=.libPaths()) It works both in ubuntu and MacOSx. I don't have Windows computer to do the same. The path used by .libPaths() are defined in one of the files used for R configuration at startup: in ubuntu: /usr/lib/R/etc/Renviron in MacosX: /Library/Frameworks/R.framework/Resources/etc/Renviron > file.path(Sys.getenv("R_HOME"), "etc", "Renviron") [1] "/Library/Frameworks/R.framework/Resources/etc/Renviron" and  ~/.Renviron ~/.Rprofile The files /usr/lib/R/etc/R

Run a R script from terminal

Let a.R being:  sayHello <- function(){    print('hello') } sayHello() In terminal, enter: Rscript a.R [1] "hello" Or: R CMD BATCH a.R Nothing is shown because the stdout() is store in a file: cat a.Rout to see the result. It is not very friendly: MacBook-Air-de-Marc:Documents marcgirondot$ cat a.Rout R version 3.4.2 beta (2017-09-19 r73321) -- "Short Summer" Copyright (C) 2017 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin15.6.0 (64-bit) R est un logiciel libre livré sans AUCUNE GARANTIE. Vous pouvez le redistribuer sous certaines conditions. Tapez 'license()' ou 'licence()' pour plus de détails. R est un projet collaboratif avec de nombreux contributeurs. Tapez 'contributors()' pour plus d'information et 'citation()' pour la façon de le citer dans les publications. Tapez 'demo()' pour des démonstrations, 'help(

Install rJava on archlinux

First, be sure that your date system is correct. timedatectl If not setup a ntp server: sudo timedatectl set-ntp true sudo pacman -S ntp sudo vi /etc/ntp.conf Replace the server with your stp server: server ntp.u-psud.fr iburst Force the date/time update and start the daemon sudo ntpd -gq sudo ntpd start Check if everything is ok timedatectl Update the system sudo pacman -Syu sudo pacman -S jdk8-openjdk sudo R CMD javareconf R In R, do install.packages("rJava") install.packages("mailR")

rJava in ubuntu

To install rJava in ubuntu, run: sudo apt - get install r - cran - rjava Alternative to get the most recent update: sudo apt-get install openjdk-8-jdk sudo R CMD javareconf sudo R install.packages("rJava")

eval() within a function

essai <- function() {   mx <- 10   eval(parse(text="k=20"), envir= environment())   print(k) } essai() # by default the environment used is .GlobalEnv # mx is not known in this environment essai <- function() {   mx <- 10   eval(parse(text="k=mx"))   print(k) } essai() essai <- function() {   mx <- 10   eval(parse(text="k=mx"), envir= .GlobalEnv)   print(k) } essai() # Here I force mx to be defined in .GlobalEnv essai <- function() {   mx <<- 10   eval(parse(text="k=mx"), envir= .GlobalEnv)   print(k) } essai() # environment() is the environment of the function essai <- function() {   mx <- 10   eval(parse(text="k=mx"), envir= environment())   print(k) } essai() essai <- function() { env <- new.env(parent = environment()) mx <- 10 eval(parse(text="k=mx"), envir= env) print(k) } essai()

install rgeos 0.3-28 without error

When I try update rgeos 0.3-24 package in R 3.4.1, I get this error: * installing to library ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library’ * installing *source* package ‘rgeos’ ... configure: CC: clang configure: CXX: clang++ configure: rgeos: 0.3-24 checking for /usr/bin/svnversion... yes cat: inst/SVN_VERSION: No such file or directory configure: svn revision:  checking for geos-config... no no configure: error: geos-config not found or not executable. ERROR: configuration failed for package ‘rgeos’ * removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgeos’ * restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rgeos’ Here is the solution. First install geos and gdal complete frameworks from here: http://www.kyngchaos.com/software:frameworks At the time I write this article, the links are here: GDAL 2.2 Complete GEOS framework v3.6.1-1 Then load the last version of