Install GTK+ for R under Windows

This short tutorial teaches you how to install GTK+ for R under windows.

Installation procedure:

• From the R command line (or in R-Studio), install the RGtk2 package by running

This might fail with the warning that package ‘RGtk2’ is not available (for R version xxx). If so, just run

to install the RGtk2 package directly from its source code (this might take a few minutes).

• Load the package by running:

This will notice the missing GTK and prompt you to install it.
Choose “Install GTK+” when prompted, it might take a few minutes to install. Afterwards it will likely still complain (restart required).

This tutorial helps you quickly learn how to do R programming.

1  Must-know Prelimibaries for Learning R

1.1 Get helps in R

• To get help on a function or a dataset:
?function_name <==> help(function_name)
For example, ?mean is equivalent to help(mean)
• To find functions using a keyword
??keyword <==> help.search(keyword)
Note that search term of multiwords shall be quoted.
For example, ??plotting is equivalent to help.search(plotting)
??”nonlinear regression” is equivalent to help.search(“nonlinear regression”)

Filtering index of vectors in R

This short tutorial talks about filtering index of vectors in R.

Read more Filtering index of vectors in R

Special and missing values in R: NA, NaN, NULL, Inf

This tutorial briefly discuss handling of missing values in R, including NA, NaN, and NULL.

1  NA vs NaN vs NULL vs Inf

• In statistical data sets, we often encounter missing data, which are represented with NA in R. The motivation of NA, meaning ‘Not Available’, is to handle the case where specifications to an operation is not complete.
• NaN, meaning ‘Not A Number’, is another kind of ‘missing’ that is produced by numerical computation when the result cannot be defined sensibly. In other words, the calculation either didn’t make mathematical sense or could not be performed properly.
• NULL represents that the value in question simply does not exist, rather than being existent but unknown.
• Inf and -Inf represent positive and negative infinities, respectively, resulting numerical calculations.

Customize environment in R

This tutorial talks about how to customize environment in R.

In R, users can customize their environment in several different ways.

1  Site initialization file

The site initialization file contain the commands that you want to execute every time R is started under your system. The location of this file is determined by following rule:

1. If the R_PROFILE environment variable is set, then it determines the location of the site initialization file;
2. Otherwise, the file Rprofile.site in the R home sub-directory etc is used.

Introduction to R Language

This tutorial presents an introduction to R programming.

1  Preliminaries

• R language is case sensitive
• R names consist of alphanumeric symbols, plus ‘.’ and ‘_’， with a restriction that a name must start with ‘.’ or a letter.
• Two kinds of basic R commands: (1) expressions (evalue, then print, then value is lost); (2) assignment (evaluate, store the value, but not print).
• Multiple commands can co-exist in one line, separated by ‘;’. Nultiple commands can also be grouped together into one compound expression by a pair of braces ‘{‘ abd ‘}’.
• We can run a R file, say example.R, by the command
> source(“example.R”)
• By default, R outputs evaluation results to the console. However, the outputs can be re-directed to a file, say output.txt, by the command
> sink(“output.txt”)
and such redirection can be stopped to resume normal console output by
> sink()
• To get the help of a function, for example, solve(), we can use the commands
>help(solve)  or
> ?solve
• The command
> objects()
returns the names of objects in the workspace under current R session, and the rm() function can be used to remove objects from the workspace
> rm(x,y,z, temp,foo)
• When exiting a R session, R prompts to ask whether to save the workspace, meaning that all objects will be saved to a .RData file, and all command lines will be saved to a .Rhistory file. Later if R is started from same directory, these history data will be loaded into R session. It is recommended that you should use separate working directory for analyses conducted with R.