DATA MINING
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 Rvariable[].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 $OS.type [1] "unix" $file.sep [1] "/" \$dynlib.ext [1] ".so" $GUI [1] "X11" $endian [1] "little" $pkgType [1] "source" > if (.Platform$OS.type == "unix") system("ls") |
There are other variables, but Rvariable[].Platform is the
recommended variable to use for programming. The variable
Rvariable[]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) i486-pc-linux-gnu locale: LC_CTYPE=en_AU;LC_NUMERIC=C;LC_TIME=en_AU;LC_COLLATE=en_AU; LC_MONETARY=en_AU;LC_MESSAGES=en_AU;LC_PAPER=en_AU;LC_NAME=C; LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU;LC_IDENTIFICATION=C 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 Sys.info
which includes machine name and type, operating system name and
version, and username.
> Sys.info() 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" user "gjw" > if (Sys.info()["sysname"] == "Linux") system("ls") |
Information about various limits of the machine (including things like
maximum integer) is obtained from the Rvariable[].Machine variable.
> .Machine \$double.eps [1] 2.220446e-16 $double.neg.eps [1] 1.110223e-16 [...] $integer.max [1] 2147483647 $sizeof.long [1] 4 $sizeof.longlong [1] 8 $sizeof.longdouble [1] 12 $sizeof.pointer [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
(Roption[]prompt and continuation prompt (Roption[]continue),
the terminal width (Roption[]width), number of digits to show when
printing (Roption[]digits, and many more. In this example we list
some of the options then change Roption[]width, storing its old
value, evaluate some other functions, then restore the original value:
> options() $OutDec [1] "." $X11colortype [1] "true" [...] $verbose [1] FALSE $warn [1] 0 $warnings.length [1] 1000 $width [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(Sys.info()["login"]) |
Copyright © Togaware Pty Ltd Support further development through the purchase of the PDF version of the book.