Video 1.1-2.4

1.1. Typing command

Please run RStudio. The window is devided into 4 sections” scripts, console, variables and other (files, plots, packages, help).

RStudio interface
RStudio interface

You can use console for typing commands for instant execution and accessing the variables. When you perform several operations it is better to write script instead. Lines of script can be run by pressing Ctrl+R.

Now, try to type some simple calculations in the console.

2*2
## [1] 4
2^10
## [1] 1024
sqrt(16)
## [1] 4
16^(1/2)
## [1] 4

1.2. Install R packages

In RStudio, you can install packages via “Packages” in the bottom-right section.

Alternatively, the following line should install a package install.packages("package_name") If this does not work:

  1. Select all repositories in “packages” menu or by calling setRepositories()

  2. If still does not work - use Bioconductor installation:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("package_name")

Do not run: in R older than v.3.5 - use biocLite

source("http://bioconductor.org/biocLite.R")
biocLite("rgl")

1.3. Calling functions

Function always have () when it is called. Try to type

log(100)

There are several ways to set function parameters

log(100, base=10)  # full parameter name
log(100, b=10)     # distinctive part of a parameter name
log(100, 10)       # no parameter name. The order defines

1.4. Embedded help

In R the vast majority of functions is well-annotated. Try some variants.

  • Note that # is a comment character. The code after # is ignored
help("sqrt")    # help on "sqrt" function
?sqrt           # ...the same...
?round
??round         # fuzzy search for "round" in all help topics
apropos("plot") # propose commands with the word "plot" inside name

There are some demos as well. They are quite old (and majority - ugly), but still we can see them.

demo()          # show available demos
demo("image")   # start demo "image"
demo(persp)
demo(plotmath)

Home Next

By Petr Nazarov