Desktop Survival Guide
by Graham Williams

System Parameters

At times you may need or want to know about the machine on which you are running. The R .Platform variable will give information about the system, and can be used, for example, to conditionally run code depending on which operating system you are on.

> .Platform
[1] "unix"

[1] "/"

[1] ".so"

[1] "X11"

[1] "little"

[1] "source"

> if (.Platform$OS.type == "unix") system("ls")

There are other variables, but .Platform is the recommended variable to use for programming. The variable version also lists information about the version of R you are running.

> version
platform i486-pc-linux-gnu
arch     i486
os       linux-gnu
system   i486, linux-gnu
status   beta
major    2
minor    2.0
year     2005
month    09
day      28
svn rev  35702
language R

> if (version$os == "linux-gnu") system("ls")
> if (version$os == "mingw32") system("dir")

For a summary of the current R session the sessionInfo function is useful:

> sessionInfo()
R version 2.4.1 (2006-12-18)


attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
[7] "base"

other attached packages:
       ROCR      gplots       gdata      gtools         ada       rpart
    "1.0-1"     "2.3.2"     "2.3.1"     "2.3.0"     "2.0-1"    "3.1-34"
    ellipse      rggobi        mice        nnet        MASS       Hmisc
    "0.3-2"   "2.1.4-4"      "1.15"    "7.2-31"    "7.2-31"     "3.2-1"
      RGtk2      rattle rcompletion
    "2.8.7"   "2.1.123"    "0.0-12"

Yet another source of system information is which includes machine name and type, operating system name and version, and username.

                             sysname                              release
                             "Linux"                   "2.6.12-1-686-smp"
                             version                             nodename
"#1 SMP Tue Sep 6 15:52:07 UTC 2005"                             "athene"
                             machine                                login
                              "i686"                                "gjw"

> if (["sysname"] == "Linux") system("ls")

Information about various limits of the machine (including things like maximum integer) is obtained from the .Machine variable.

> .Machine
[1] 2.220446e-16

[1] 1.110223e-16


[1] 2147483647

[1] 4

[1] 8

[1] 12

[1] 4

A call to capabilities will list optional features that have been compiled into your version of R:

> capabilities()
    jpeg      png    tcltk      X11 http/ftp  sockets   libxml     fifo
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE
  cledit    iconv      NLS
    TRUE     TRUE     TRUE

The options function in R allows numerous characteristics of the running R session to be tuned. The options function without arguments returns a list of options and their values. Use getOption to get a specific option value, and options itself to set values. Options that can be set include the prompt string (prompt and continuation prompt (continue), the terminal width (width), number of digits to show when printing (digits, and many more. In this example we list some of the options then change width, storing its old value, evaluate some other functions, then restore the original value:

> options()
[1] "."

[1] "true"



[1] 0

[1] 1000

[1] 80

> getOption("width")
[1] 80
>ow <- options(width=120)
> options(ow)

Other useful functions include:

> R.home()		# Location of R installation: /usr/lib/R
> Sys.sleep(5)		# Sleep for 5 seconds.
> proc.time()           # shows how much time is currently consumed
> Rprof("Rprof.out")    # Profile the execution of R expressions
> system.time([...])	# Execute a command and report the time taken
> on.exit([...])        # Execute commands on exit or interruption
> username <- as.vector(["login"])

Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.