# R Programming/Utilities

R Programming
* R Basics
** Introduction
** Sample Session
** Manage your workspace
** Settings and Installation
** Documentation
** Control Structures
** Working with functions
** Debugging
** Using C or Fortran
** Utilities
** Estimation utilities
** Packages
* Data Management
** Data types
** Working with data frames
** Importing and exporting data
** Text Processing
** Times and Dates
* Graphics
** Grammar of graphics
* Publication quality output
* Descriptive Statistics
* Mathematics
** Optimization
** Probability Distributions
** Random Number Generation
* Statistical Core Methods
** Maximum Likelihood
** Method of Moments
** Bayesian Methods
** Bootstrap
** Multiple Imputation
** Nonparametric Methods
* Regression Models
** Linear Models
** Quantile Regression
** Binomial Models
** Multinomial Models
** Tobit And Selection Models
** Count Data Models
** Duration Analysis
* Time Series
* Factor Analysis
* Classification
** Ordination
** Clustering
* Network Analysis
* High Performance Computing
** Profiling R code
** Parallel computing with R
* Appendix
** Sources
** Index
This page includes material about some utilities. Most of the functions presented here have nothing to do with statistical analysis but may be useful when working on a project. Many functions are just similar to standard unix functions.

## System (Unix/DOS)

system gives access to the system (DOS or unix). The option wait=FALSE means that you don't ask R to wait that the task is finished.
Some examples :
* You can convert an image from to PS to PNG using the unix convert function of your computer. If you want to know more about this function, open a Terminal application and type man convert (This should work on Mac OS and Linux).
* You can open Stata and run a program.
* You can run pdflatex from R and directly open the pdf in a pdf browser.
See also sys in the Hmisc package, shell and shell.exec.

## File Handling

dir lists all the files in a directory. It is similar to the Unix function ls. dir.create creates a new directory. It is similar to mkdir in Unix.
file.info gives information about a file.
Removing files with a specific pattern :
* file.edit opens a file in the text editor.
* file.show opens a file in a new window.
* tempfile creates a temporary file.
* getZip in the Hmisc package.

## Internet

browseURL opens a URL using an internet browser. download.file download a file from the internet.
To see the default browser, use getOption
We can change the default browser using the options command. It is safer to store the options before.
You can download a file from the internet using download.file. Note that very often you don't need to download a file from the internet and you can directly load it into R from the internet using standard functions. For instance, if you want to read a text file from the internet, you can use read.table, scan or readLines.
See also RCurl

## Computing time

If you perform computer intensive task you may want to optimize the computing time. Two functions are available system.time and proc.time. Both returns a vector of values. The first is the standard CPU time.

## Computing process

user.prompt (Zelig) makes a pause in the computation process (useful if you want to do a demo). waitReturn (cwhmisc) does the same job. Sys.sleep stop the computation during a few seconds.
It is possible to stop the computing process if a logical condition is not true using stopifnot.

## Miscellanous

* trCopy (TinnR package) copy an object to the clipboard. It is useful if you want to copy a large object to the clipboard. For instance, if you want to copy the code of a function and paste it in a text editor.
* sessionInfo gives information on the current session info (R version + loaded packages). This function may be useful for reproducible computing. getRversion gives the current R version. R.version gives more details about the computer and R.Version returns the same informations as a list.

## See Also

* See the R.utils package

## References

* ↑ Henrik Bengtsson (2009). R.utils: Various programming utilities. R package version 1.1.7. http://CRAN.R-project.org/package=R.utils