Articles

Density of beta distribution

The density of beta distribution in R is obtained by: dbeta(x, shape1, shape2, ncp = 0, log = FALSE) Arguments x      vector of quantiles shape1, shape2      non-negative parameters of the Beta distribution. In package HelpersMG, I propose the  dbeta_new(x, mu = NULL, v = NULL, shape1, shape2, ncp = 0, log = FALSE) with mu being the mean and variance being v To obtain a uniform distribution with mu and v, use: mu=0.5 and v=1/12 or shape1=1 and shape2=1

POSIXct or POSIXlt

POSIXct are easier to work with as data (e.g. a column in a dataframe). POSIXlt is easier to work with as dates & times, and has a bigger range. To remember which one is doing what: lt is for list. 'ct' is great for representing date/time holistically (2021-04-26 13:21:27) and is numeric under the hood in seconds since the big bang (just kidding), kind of like julian seconds. [note that "Julian seconds" is misleading. It should be rather ordinal seconds] 'lt' is a list of 7 elements that often require manipulation (e.g. lt$mon = month of the year starting with Jan = 0) but it's great for extracting values like day of the year, day of the week, etc. w/o having to do it yourself - saves a heap of error-fraught coding. One draw back is the handling of daylight savings shifts. In March, an hour gets lost (jumps from 0159 to 0300) and in October you get an hour twice, so if you're using code that requires 1 hour steps, you get hiccups twice/year, so tha...

R stuck during S3 registration check

This worked for me to apparently fix my system: Start with a newly rebooted system. Uninstall XQuartz by dragging it to the trash. Look in /Library/LaunchAgents/ for filenames related to xquartz.  Delete them. Look in /Library/LaunchDaemons/ for similar files.  Delete them. Reboot the system again, and install XQuartz again. Relogin, and things seem fine. ______ Sometimes, just reinstalling XQuartz is sufficient. https://www.xquartz.org

Install plumber server

This is intended for a Ubuntu 20.04 server: sudo apt-get install git-core libssl-dev libcurl4-gnutls-dev curl libsodium-dev libxml2-dev sudo R install.packages("plumber") q("no") mkdir plumberapp cd plumberapp vi plumber.R ## Copy these lines # plumber.R #* Echo back the input #* @param msg The message to echo #* @get /echo function(msg="") {   list(msg = paste0("The message is: '", msg, "'")) } ## End vi myapi.R ## Copy these lines r <- plumber::plumb("/home/mgirond/plumberapp/plumber.R") r$run(host="0.0.0.0", port=8000) ## End vi my-api.service ## Copy these lines [Unit] Description=plumber service [Service] ExecStart=/usr/bin/Rscript /home/mgirond/plumberapp/myapi.R [Install] WantedBy=multi-user.target ## End sudo ufw allow 8000/tcp cp my-api.service /etc/systemd/system/my-api.service systemctl start my-api systemctl enable my-api sudo reboot Then it is possible to test the API: curl "http://localh...

open the working directory as a window in finder

Simply enter: system(command=sprintf('open %s', shQuote(getwd()))) It has been introduced in HepersMG package > 4.5-1 as the function openwd() https://CRAN.R-project.org/package=HelpersMG   install.packages("https://hebergement.universite-paris-saclay.fr/marcgirondot/CRAN/HelpersMG.tar.gz", repos=NULL, type="source") library(HelpersMG) openwd() It should work also for windows with  shell.exec(getwd())

Reset "par" with defaut values

Enter in R or Rstudio and do: dput(par(no.readonly = TRUE)) Copy the list() that is shown, for example for me: list(xlog = FALSE, ylog = FALSE, adj = 0.5, ann = TRUE, ask = FALSE,     bg = "white", bty = "o", cex = 1, cex.axis = 1, cex.lab = 1,     cex.main = 1.2, cex.sub = 1, col = "black", col.axis = "black",     col.lab = "black", col.main = "black", col.sub = "black",     crt = 0, err = 0L, family = "", fg = "black", fig = c(0,     1, 0, 1), fin = c(9.47674418604651, 8.72093023255814), font = 1L,     font.axis = 1L, font.lab = 1L, font.main = 2L, font.sub = 1L,     lab = c(5L, 5L, 7L), las = 0L, lend = "round", lheight = 1,     ljoin = "round", lmitre = 10, lty = "solid", lwd = 1, mai = c(1.02,     0.82, 0.82, 0.42), mar = c(5.1, 4.1, 4.1, 2.1), mex = 1,     mfcol = c(1L, 1L), mfg = c(1L, 1L, 1L, 1L), mfrow = c(1L,     1L), mgp = c(3, 1, 0), mkh = 0.001, new = FAL...

Install tiff, ijtiff and jpeg packages in Ubuntu and MacOSX

In terminal, first install wget to download sources of the packages. Check the most recent sources in CRAN web site. brew install wget For tiff packages, in MacOSX, Intel computer  brew install libtiff sudo ln -s  /usr/local/include/tiff.h /Library/Frameworks/R.framework/Resources/include/ sudo ln -s /usr/local/include/tiffconf.h /Library/Frameworks/R.framework/Resources/include/ sudo ln -s /usr/local/include/tiffio.h /Library/Frameworks/R.framework/Resources/include/ sudo ln -s /usr/local/include/tiffvers.h /Library/Frameworks/R.framework/Resources/include/ sudo ln -s /usr/local/lib/libtiff* /Library/Frameworks/R.framework/Resources/lib/ cd $HOME wget https://cran.r-project.org/src/contrib/tiff_0.1-8.tar.gz R CMD INSTALL --configure-vars='INCLUDE_DIR=/usr/local/include LIB_DIR=/usr/local/lib' tiff_0.1-8.tar.gz rm tiff_0.1-8.tar.gz For ijtiff In R: install.packages(c("checkmate", "strex", "zeallot")) In terminal:  wget https://cran....