# Comments on “Introduction to Scientific Programming and Simulation Using R”

September 17, 2009
By

(This article was first published on Jeromy Anglim's Blog: Psychology, Statistics, & Research Design, and kindly contributed to R-bloggers)

I’ve just been reading Introduction to Scientific Programming and Simulation Using R by Owen Jones, Robert Maillardet, and Andrew Robinson.

It seems like it would make a good introductory book for a course on, as the title suggests, scientific programming. It provides an introduction to computer programming concepts and how to use R. It then goes on to discuss “numerical techniques”, “probability and statistics”, and “simulation”. It has end of chapter exercises and a package on CRAN (spuRs). It even has an example from the AFL. My guess is that one of the authors is a Richmond supporter.

I’ve read a lot of R books and I’m always on the look out for some useful suggestions. The following are an assortment of random little tips that I took away from the first few chapters of the book:

• sessionInfo() displays attached packages.
• I knew that pdf(); ...plot code...; dev.off() could be used to save a plot to a pdf file. I didn’t know that in order to save lattice plots, you need to print() the plot.
• The write function converts data to vectors and defaults to one column per element for character code and five for numeric. I now understand that if I want to produce a matrix with write, I need to align the ncolumns argument with the number of columns in the matrix.
• list(); unlist(); lapply(); sapply() provide some cool options for working with objects in R.
• stop("Reason for stopping") can be used to end a function call with a warning message.
• system.time(expression) is a good way to examine the time taken by a function or set of expressions.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...