Articles

Affichage des articles du novembre, 2019

Permission error in install packages in Ubuntu

If you have errors like: permission denied, enter these commands cd /usr/lib/ sudo chmod -R a+w R cd /usr/share/ sudo chmod -R a+w R ______________________________________ If you have this error in Ubuntu 22.04 lib = "/usr/local/lib/R/site-library"' ne peut être ouvert en écriture Try: cd /usr/local/lib/R sudo chown -R root:staff site-library sudo chmod -R 02775 site-library

Catalina installation

After the installation of Catalina (MacOSX 10.15), I had several problems: - I was forced to accept that RStudio 1.3.572 had access to all the files of the computer; - I cannot compile; I had this message: fatal error: _stdio.h: No such file or directory  #include <_stdio.h> I try this xcode-select --install

tiff, png or jpg pictures

From an answer in r-help list: Question: Whether I use tiff, png, jpeg, or pdf I always see vertical and horizontal lines at every grid increment on the plots. Answer by colin@colinsmith.org : This problem comes from the way Quartz renders immediately adjacent filled polygons. To get around it, you can add type=“cairo” or type=“Xlib” as an argument to the tiff, png, or jpeg call.

° symbol and other unicode codes in knitr

To use ° symbol in knitr or sweave, first load the latex package gensymb  and after use this code $ \degree $. Then the beginning of your code should be something like that: \documentclass[a4paper]{article} \usepackage{gensymb} If the package gensymb is not present, alternative is to do: \documentclass[a4paper]{article} \DeclareTextSymbol{\degree}{OT1}{23} ############################################### To use the ° symbol within a chunk, you must define the encoding. Be sure also to save the .Rnw file using the same encoding (command File -> Save with encoding... in Rstudio). For latin1: \documentclass[a4paper]{article} \usepackage[latin1]{inputenc} \begin{document} <<>>= degree <- "°" print(degree) @ \end{document} For utf8 (based on a remark of  Yihui Xie in r-help list): If you use pdflatex, you have to declare the font encoding \usepackage[T1]{fontenc} when you save the document with UTF-8: \docum

How to deal with character(0)

Let x <- character(0) x == character(0) returns logical(0), which is not what we expect. A solution is to test: identical(x, character(0)) But it does not work if x has attributes. Then, do: attributes(x) <- NULL identical(x, character(0)) or  (length(x) == 0) && (typeof(x) == "character")

Convert Lat-Lon to UTM and reverse

Image
library(PBSmapping) utm <- structure(list(x = c(160915.9, 161253.9, 161253.9),  y = c(2573771, 2573763, 2573763)), .Names = c("x",  "y"), row.names = c(NA, -3L), class = "data.frame") datainUTM<-data.frame(cbind(utm$x/1000,                              utm$y/1000,                              rep(0, dim(utm)[1]),                              1:dim(utm)[1])) names(datainUTM)<-c("X", "Y", "PID", "POS") attr(datainUTM, "projection") <-"UTM" attr(datainUTM, "zone") <-18 datosLL<-convUL(datainUTM) > datosLL          X       Y PID POS 1 -78.3133 23.2383   0   1 2 -78.3100 23.2383   0   2 3 -78.3100 23.2383   0   3 Alternative library(sp) library(rgdal) orig <- data.frame(lat = c(23.2383,23.2383,23.2383),                     long = c(-78.3133,-78.3100,-78.3100),                     elv = c(4.01, 4.00, 4.00)) coordina

User Agent of any browser

http://www.useragentstring.com Can then be used in Rcurl: require(RCurl) require(XML) webpage <- getURLContent(" http://www.useragentstring.com ", useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11")

strptime() with %p option in non-US locale

The option %p of the hour format for strptime() function requires that locale is set to US: > Sys.getlocale(category = "LC_TIME") [1] "fr_FR.UTF-8" > strptime("2004-01-17 12:49 AM", format="%Y-%m-%d %I:%M %p") [1] NA > Sys.setlocale(category = "LC_TIME", locale = "en_US.UTF-8" ) [1] "en_US.UTF-8" > strptime("2004-01-17 12:49 AM", format="%Y-%m-%d %I:%M %p") [1] "2004-01-17 00:49:00" If your system does not allow to use  "en_US.UTF-8", just indicate "C"