```
If you are using Ubuntu/Linux, you can install
libcurl4-gnutls-dev and problem solved!
In your shell:
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libssl-dev
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libxml2-dev
```

## Archive for the ‘ R ’ Category

# Problems installing the devtools package (Ubuntu)

Author: Fabio FajardoNov 25

# R online!

Author: Fabio FajardoJul 1

Todo mundo sabe da importância das linguagens de programação no mundo moderno e mais ainda para análise das dados. **R** é um ambiente computacional e uma linguagem de programação cuja popularidade cresce rapidamente. A linguagem é ótima para o tratamento, análise e visualização gráfica de dados. Hoje é considerado o melhor ambiente computacional para essa finalidade.

Existem milhares de *sites* que disponibilizam material para aprender a programar no **R** (https://blog.ufes.br/fabiomolinares/2017/04/26/free-100-online-tutorials-for-r-programming-statistics-and-graphics/). Mas, o acesso online pode facilitar a vida de um iniciante quando tenta usá-lo num equipamento que não o tenha instalado ou ainda está no celular e quer fazer uso rápido do R.

Vou listar algumas alternativas que já usei:

- https://rnotebook.io/ (Roda Jupyter R notebooks online)
- http://www.r-fiddle.org/ (or https://cdn.datacamp.com/dcl-react-prod/example.html)
- https://repl.it/languages/rlang
- https://www.jdoodle.com/execute-r-online
- https://www.tutorialspoint.com/execute_r_online.php
- https://rweb.stat.umn.edu/Rweb/Rweb.general.html
- https://rdrr.io/snippets/
- https://rextester.com/l/r_online_compiler

# Free 100 Online tutorials for R programming, Statistics and Graphics

Author: Fabio FajardoApr 26

Here is a list of FREE R tutorials hosted in official website of universities around the world. The tutorials are listed in no particular order, actually based on when I have discovered it. They will be categorised soon. Please kindly suggest me other university-hosted online R tutorials by email to me@pairach.com.

## A list of R tutorials, which are not hosted in the webpages of academic institutes can be found here.

**University of Oxford**Modern Applied Statistics with S, 4edn (On-line material)[url]

by W. N. Venables and B. D. Ripley**University of California at Davis**

Getting Started with the R Data Analysis Package [url]

by Norm Matloff**Clarkson University**

R Tutorial [url]by Kelly Black

**York University**

Getting started with R [url]**University of Waterloo**

R Tutorial For Windows and Unix Environment [url]**University of California at Los Angles, UCLA**

Resources to help you learn and use R [url]**University of California at Riverside**

Programming in R [url]**University of Illinois**

A Brief Introduction to R [url]**University of Texas at Austin**

R Tutorial Videos [url]by Brandon K. Vaughn

**University of California at Berkeley**

An Introduction to R (pdf)

by Phil Spector**Chiang Mai University**

Econometrics with R (in Thai) [url]

by Pairach Piboonrungroj**University of California at Santa Babara**

R Programming Resource Centre [url]

by National Center for Ecological Analysis and Synthesis**University of Carnegie Mellon**

A Tutorial: Some Fundamentals of R [url]

by Bruce E. Trumbo**University of Illinois State**

R Tutorial [url]

by Dong-Yun Kim**University of MacMaster**

Introduction to the R Statistical Computing Environment [url]

by John Fox.**University of Princeton**

Introducing R [url]

by Germán Rodríguez**University of Amsterdam**

How to draw graphs with R (Graphics) [url]

by Angelos-Miltiadis Krypotos**University of North Texas**

Do it yourself – Introduction to R (Intro) [url]**University of Warwick**

R programming page [url]

(Biosciences: Molecular Organisation and Assembly in Cells)

by Peter Cock.**University of Illinois at Urbana-Champaign**

R tutorial for Applied Econometrics [url]

by Prof. Roger Koenker

**Coastal Carolina University**

R tutorials (General) [url]

by William B. King**University of Colorado Denver**

R Tutorial (General)[url]

by Stephanie Santorico and Mark Shin**Stanford School of Medicine (Biomedical Informatics)**

R Tutorial (VDO on Introduction + Translational Bioinformatics (url)**Harding University**

Producing Simple Graphs with R (basic graphic e.g., line, bar, hist, line) (url)

by Frank McCown**University of Kentucky, Department of Statistics**

Use Software R to do Survival Analysis and Simulation [pdf]

by Mai Zhou**University of Pittsburgh, Department of Statistics**

Time Series Analysis and Its Applications: With R Examples[url]

by R.H. Shumway & D.S. Stoffer**University of Toronto**

R Tutorial (for Ecology) [url]

by the Cadotte Lab**Florida State University**

Use R for Climate research [url]

by James B. Elsner & Thomas H. Jagger**University of Washington**

Introduction to R [url]

by Jinyoung Kim**Lancaster University**(UK)

R tutorial [url]

by Joe Whittaker**University of Georgia Athens**A short R tutorial [pdf]

by Steven M. Holland**University of Twente**

R tutorials [url]

(more than 1o tutorials about R in pdf + data & code)

by D G Rossiter**Vrijie University Amsterdam, Netherlands**

Handleiding R (in Dutch) [pdf]

by A.W. van der Vaart**University of Wisconsin-Madison**

Introduction to R [url]

by Karl W Broman**City University of New York**

simpleR Using R for Introductory Statistics [url]

by John Verzani**Pomona College**

An R tutorial [pdf]

by Jo Hardin**University of Alaska Fairbanks**

Using R [url]

by the Biology & Wildlife Department computer**University of Bath**

Practical Regression and Anova using R [pdf]

Julian J. Faraway**University of Goettingen**

Time Series Analysis with R – Part I [pdf]

by Walter Zucchini and Oleg Nenadíc

Statistical Analysis with R – a quick start – [pdf]

by Oleg Nenadíc and Walter Zucchini**University of Washington, Department of Economics**Working with Time Series Data in R [pdf]

by Eric Zivot**University of Liège, Faculty of Engineering**

Using R for Linear regression [pdf, 9 pages]

by Kristel Van Steen**University of Cambridge**

Local tips for R [url] – in both statistics & graphics

by Rudolf Cardinal**Montana State University, Department of Mathematical Sciences**

Introduction to Sweave (R+LaTeX) [url]

by Jim Robison-Cox**Stanford University**

Social Network Analysis in R [url] including source R files and outputs

by McFarland, Daniel A., Solomon Messing, Michael Nowak and Sean J. Westwood.**Ludwig-Maximilians-University Munich**(Germany)

Sweave (R + LaTeX) [url] including manuals and example files

by Friedrich Leisch**Ecole Polytechnique Fédérale de Lausanne**

Sweave = R • LaTeX^2 (pdf, slides)

by Nicola Sartori**University of Auckland**

Four course on Statistical Computing and Graphics including document, R codes (pdf)

by Ross Ihaka**Nova Southeastern University**

Many R tutorials using Tegrity-based video tutorials (url)

by Thomas W. MacFarland**Penn State University**

– Introduction to R (get started) [url]

– Welcome to STAT 497C – Topics in R Statistical Language! [url]**Carnegie Mellon University**

Open & Free Course on Statistics (with applications in R among other software) [url]**Centre for Mathematical Sciences, Lund University**

Exception handling in R [url]

Object-oriented programming with references using S3/UseMethod [url]

by Henrik Bengtsson**University of Edinburgh**

Data Mining and Exploration (with examples with R) [url]

by Charles Sutton**University of Washington**

Survey analysis in R [url]

by Thomas Lumley**Department of Psychology, University of Pennsylvania**

Notes on the use of R for psychology experiments and questionnaires [url]

by Jonathan Baron and Yuelin Li**College of Staten Island, Department of Mathematics**simpleR: Using R for Introductory Statistics [url]

By John Verzani**Vanderbilt University**

rApache Manual [url]**University of Aarhus, Department of Computer Science – Daimi, Faculty of Science**

RPy — R from Python [url]**University of Auckland**

Many documents and links about R [url]

By Paul Murrell**National Institute of Genetics (Japan)**

R Graphical Manual [url]

By Osamu Ogasawara and IMS Lab Inc. Japan**Montana State University**

R Labs for Vegetation Ecologists [url]**University of Auckland**

Introduction to Data Technologies: Basic introduction to a number of computer technologies for working with data (HTML, XML, Databases, SQL, regular expressions, and R) [url]

by Paul Murrell**Department of Statistics and Actuarial Science, SFU**

Technical Notes on the R programming language [url]

by Sigal Blay**University of Vienna**

Stattconn Project [url]

by Thomas Baier and Erich Neuwirth**Gunma University (Japan)**

R による統計処理 [url]

by Shigenobu AOKI**Tsukuba Office, Agriculture, Forestry and Fisheries Research Council****Secretariat**

R Tips (in Japancese) [url]**University of Western Ontario, Department of Statistical & Actuarial Sciences**

Debugging in R [url]

by Duncan Murdoch**University of Sunderland**

Programming in R [url]

by Harry Erwin**Smith College, Department of Mathematics and Statistics**

Use of R as a toolbox for mathematical statistics exploration [url]

by Nicholas J. Horton, Elizabeth R.Brown and Linjuan Qian**Katholieke Universiteit Leuven**

R and Statistics [url]

by Guido Wyseure**Iowa State University**

Introduction to R [url]

by Di Cook**Cambridge University**

Graph redesign in R [url]

by Stephen J. Murdoch**Trinity College Dublin**

R Podcasts [url]

by Andrew Jackson**University of Arizona**

Introduction to R [url]

by Caroline R.H. Wiley**Cambridge University**

ESS: Emacs Speak Statistics [url]

by Stephen Eglen**Columbia University**

Running WinBugs and OpenBugs from R [url]

Andrew Gelman**University of Bremen**

vim R plugin for Linux/Unix [url]

Johannes Ranke**Montana State University**

R Web: Statistical Analysis on the web. [url]

by Jeff Banfield**University of Florida**

R for Categorical data analysis [html]

by Brett D. Presnell**University of Auckland**

An S (and R) Programming Workshop in 2003 (including slides, data and codes) [html]

by The Quartet (affiliations at that moment)

(1) Bill Venables (CSIRO, Australia)

(2) Robert Gentleman (Harvard University)

(3) Ross Ihaka (University of Auckland)

(4) Paul Murrell (University of Auckland)**Australian National University , Mathematical Science Institute**

Data Analysis and Graphics Using R – An Example-Based Approach [url]

by John Maindonald and John Braun**The Hebrew University**

Introduction to Statistical Thinking (With R, Without Calculus) [pdf]

by Benjamin Yakir**Basel Institute for Clinical Epidemiology and Biostatistics**Tutorial: ggplot2 [pdf, 14 p.]

by Ramon Saccilotto, Universitätsspital Basel**UC, Davis: Bioinformatics**

Data Analysis and Visualization Course, 2012 (links to many sessions during two days of the course)

by Vince Buffalo, Joe Fass, Jie Peng and Dawei Lin**University of Warwick**

R useR! Conference 2011 (links to materials and documents of the tutorials, invited talks and presentations)

by Department of Statistics, University of Warwick**Vanderbilt University**

R useR! Conference 2012 (links to materials and documents of short courses, tutorials, invited talks and presentations)

by Department of Statistics, Vanderbilt University**Technische Universität Wien, Vienna, Austria**

useR! 2004: The 5th International R useRs Conference (links to materials of the conference)

DSC 1999: The 1st conference for the developers of statistical software and researchers in statistical computing

DSC 2001: The 2nd conference for the developers of statistical software and researchers in statistical computing

DSC 2003: The 3rd conference for the developers of statistical software and researchers in statistical computing

by Department of Statistics and Probability Theory,Technische Universität Wien**The University of Auckland**

DSC 2007: The 5th conference for the developers of statistical software and researchers in statistical computing

(Workshops, Program, papers and posters)

by Department of Statistics, The University of Auckland**University of Oxford**

APTS Computer-Intensive Statistics 2012 (html) – Lecture note, datasets and codes

by Prof. Brain Ripley**Simon Fraser University**

Technical Notes on the R programming language

by Sigal Blay**University of Florida**

Introducing Monte Carlo Methods with R (pdf)

by Christian P. Robert George Casella**University of Tennessee**

pbdR — Programming with Big Data in R (html)

Remote Data Analysis and Visulization Center**National Center for Ecological Analysis and Synthesis**

**The Regents of the University of California**

– Integrate C Language Functions into R With an R Package

– R: A self-learn tutorial**Ghent University**

Teaching materials (slides, codes and datasets) for using lavaan package for Structural Equation Modeling (link)

by Yves Rosseel**Calvin College**

Computational Statistics Using R and R Studio – An Introduction for Scientists (pdf)

by Randall Pruim**Department of Mathematical Sciences**

**Aalborg University, Denmark**

Graphical Models with R (pdf)

Soren Hojsgaard**Statistics Department**

**Carnegie Mellon University**

Writing R Functions (pdf)

by Cosma Shalizi**Institute for Environmental Sciences**

**University Koblenz-Landau**

Lecture “Applied Multivariate Statistics” 2011/2012 (url)

by Ralf Schäfer**University of Groningen, The Netherlands**

R Tutorial for Applied Statistics (URL)

by Anne Boomsma**University of Florida**

Tutorial on Making Simple R Packages (URL)**University of Göttingen – Georg-August-Universität Göttingen**

Time Series Analysis with R – Part I (PDF)

by Walter Zucchini, Oleg Nenadi´c**Harvard University**

Quick Introduction to Graphics in R Introduction to the R language (pdf)

by Aedin Culhane**University of Pennsylvania**

R Study Group (General guide to R) (URL)

Josef Fruehwald

# Problems installing the devtools package in Ubuntu

Author: Fabio FajardoJun 7

You want to use the ** devtools** package. Suposse that you have run the following commands:

```
> install.packages("devtools", dependencies = TRUE)
...
> library(devtools)
Error in library(devtools) : there is no package
called ‘devtools’
The 'devtools' package was not installed!
```**
Solution: **

I installed libcurl4-gnutls-dev and the
problem was solved.

In your shell:

```
apt-get -y build-dep libcurl4-gnutls-dev
apt-get -y install libcurl4-gnutls-dev
```

# How to update R software in windows?

Author: Fabio FajardoFeb 9

- Install the package using
**install.packages(“installr”)** - Load package with
**library(“installr”)** - Use the function
**updateR()**to update!

- It checks for a newer version of R.
- If one exists, the function will download the most updated R version and run its installer.
- Once done, the function will offer to copy (or move) all of the packages from the old R library to the new R library.
- It will then offer to update the moved packages, offer to open the new Rgui, and lastely, it will quit the old R.

# A sphere in R using rgl package

Author: Fabio FajardoJun 3

`The `

**rgl.spheres** function is a fantastic way to plot spheres! Look at!

library("rgl") rgl.spheres(1,1,1,radius=1,color="blue")

# It’s possible to read command line parameters from an R script?

Author: Fabio FajardoJun 2

YES! yes, it’s very simple. I will describe the procedure:

1. You should create the file with code R. Command-line parameters are accessible via `commandArgs()`

`.`

2. You can use ** Rscript** on all platforms, including Windows. It will support

`commandArgs()`

`, for example: In the terminal`

`Rscript myscript.R arg1 arg2 arg3`

arg1, arg2 and arg3 are arguments into your R script. If your args are strings with spaces in them, enclose within double quotes. There are two add-on packages on CRAN — getopt and optparse — which were both written for command-line parsing.

Tiny example: script.R

```
options(echo=TRUE) # To see commands in output file
args <- commandArgs(trailingOnly = TRUE)
# trailingOnly=TRUE means that only your
# arguments are returned
print(args)
start_date <- as.Date(args[1]) # First argument
figure_name <- args[2] # Second argument
n <- as.integer(args[3]) # Third argument
rm(args)
# Some computations:
x <- rnorm(n)
postscript(paste(figure_name,".eps",sep=""))
plot(start_date+(1L:n), x,type="l")
dev.off()
summary(x)
```

To run:

Rscript script.R 02/06/2015 figure 1000

# Booktabs package and Sweave

Author: Fabio FajardoMay 30

The booktabs package in latex makes really beautiful tables. This package provide some additional commands to enhance the quality of table in LaTeX, especially if there is math in your table that might run up against the regular `\hline`

in the tabular environment. I created a table with the following code:

% file: example.Rnw % require xtable \documentclass{article} \usepackage{booktabs} \begin{document} \begin{table}[!h] \centering \caption{This is my table.} \label{tab:table1} <<mytable,echo=F,results=tex>>= mat <- as.data.frame(matrix(runif(25),nrow=5)) colnames(mat) <- c("$\\alpha$","$\\beta$", "$\\gamma$","$\\delta$","$\\frac{\\epsilon}{2}$") rownames(mat) <- c(‘A’,’B’,’C’,’D’,’E’) mat <- xtable::xtable(mat,digits=rep(5,ncol(mat)+1)) print(mat, sanitize.text.function = function(x){x}, floating=FALSE, hline.after=NULL, add.to.row=list(pos=list(-1,0, nrow(mat)), command=c('\\toprule\n', '\\midrule\n','\\bottomrule\n'))) @ \end{table} \end{document}

You can use to compile:

$ R CMD Sweave example.Rnw $ pdflatex example.tex

The definition of **\toprule**, **\midrule** and **\bottomrule** from

booktabs package is:

\def\toprule{\noalign{\ifnum0=`}\fi \@aboverulesep=\abovetopsep \global\@belowrulesep=\belowrulesep \global\@thisruleclass=\@ne \@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}

\def\midrule{\noalign{\ifnum0=`}\fi \@aboverulesep=\aboverulesep \global\@belowrulesep=\belowrulesep \global\@thisruleclass=\@ne \@ifnextchar[{\@BTrule}{\@BTrule[\lightrulewidth]}}

\def\bottomrule{\noalign{\ifnum0=`}\fi \@aboverulesep=\aboverulesep \global\@belowrulesep=\belowbottomsep \global\@thisruleclass=\@ne \@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}

# Adding regression line equation and R Square on graph

Author: Fabio FajardoMay 30

```
set.seed(34567)
```

`x <- runif(10); y <- 4*x+rnorm(10) fit <- lm(y~x) r2 <- summary(fit)$r.squared # plot data and regression line plot(x, y) abline(fit, col=2) # add text to plot with legend()`

`legend('topleft', title='option 1', legend=sprintf("y = %3.2fx %+3.2f, R\UB2 = %3.2f",`

`coef(fit)[2]`

`,`

`coef(fit)[1]`

`, r2), bty='n', cex=0.7) # if you prefer a space between plus/minus and b b<-`

`coef(fit)[1]`

`if(b<0) {b_sign='-'; b=-b} else {b_sign= '+'} legend('topright', title='option 2', legend=sprintf("y = %3.2f x %s %3.2f, R\UB2 = %3.2f", coef(fit)[2],b_sign,b,r2), bty='n',cex=0.7)`

`Important:`

R\UB2B2defined R square symbol.B2is the hex code for UTF-8 character²and\Uis a control sequence that will call that character.

# Decimal places in R plot legend?

Author: Fabio FajardoMay 30

For specifying the number of digits, tipically we use the command **round**, for example:

`round(pi, digits=2)`

[1] 3.14

However, we can also use ** sprintf** command to deal with both the number of digits and the + or – in your equation, for example:

sprinf(“%3.2f”,pi)

[1] “3.14”

`Note that, `

forces the ** 3.2f** controls the number of digits and the symbol

**%**

**+**or

**–**sign in a equation.