R is a versatile, open source programming/scripting language that's useful both for statistics but also data science. Inspired by the programming language [
How to run
You can run
R interactively or in batch mode.
e.g. type in
R from the shell. The window that appears is called the R console. Any command you type into the prompt is interpreted by the R kernel. An output may or may not be printed to the screen depending on the types of commands that you run.
You can also run one or more R scripts in batch mode.
$ R CMD BATCH script_1.R script_2.R
You can also script inline using
# Notice how we use a semi-colon to separate multiple commands in a single line $ Rscript -e "library(knitr); knit('script.Rmd')"
Viewing objects in your global environment and how to clean them up
List objects in your current environment
remove objects from your current environment
x <- 5 rm(x) x
## Error: object 'x' not found
remove all objects from your current environment
rm(list = ls())
Notice that we have nested one function inside another.
# signs to comment. Comment liberally in your R scripts. Anything to the right of a
# is ignored by R.
<- is the assignment operator. Assigns values on the right to objects on the left. Mostly similar to
= but not always. Learn to use
<- as it is good programming practice. Using
= in place of
<- can lead to issues down the line.
install.packages("package-name") will download a package from one of the CRAN mirrors assuming that a binary is available for your operating system. If you have not set a preferred CRAN mirror in your
options(), then a menu will pop up asking you to choose a location.
old.packages() to list all your locally installed packages that are now out of date.
update.packages() - will update all packages in the known libraries interactively. This can take a while if you haven't done it recently. To update everything without any user intervention, use the
ask = FALSE argument.
update.packages(ask = FALSE)
q() and answer
y to quit.