Rprof

Rprof(filename)
Examine which commands are taking up the most time in an R script or function. I’d call this a crapshoot since Rprof doesn’t typically indicate a particular line of code that is taking a disproportionate amount of time. However, Rprof is easy and quick to implement, so it may serve as a nice first attempt to identify what is making code run slowly.
  • filename – A file name where to store results.

Continue reading

append

append(x, values, after=length(x))
Append values to x, possibly inserted into the middle of x. This function is important since it tends to perform a little faster than using the concatenation (c) function.
  • x – A vector.
  • y – Another vector to place at the end of or within x.
  • after – Where values should go in x, by default at the end.

Continue reading

ifelse

ifelse(test, yes, no)
The ifelse function is used to assign one object or another depending on whether the first argument, test, is TRUE or FALSE. It even works as one would hope when test is a vector.
  • test – A logical expression, which may be a vector.
  • yes – What to return if test is TRUE.
  • no – What to return if test is FALSE.

Continue reading

apply

apply(x, margin, function, …)
apply implements a function across the rows or columns of a matrix. It also works on multidimensional arrays and can be used to apply functions across one or more dimensions of those arrays.
  • x – A matrix or array.
  • margin – The dimension of the matrix or array x to preserve. If x is an array, then this may be a vector indicating each dimension that should be preserved.
  • function – A function (e.g. mean) to be applied across each dimension not listed in margin. In a matrix, the function would be applied across the rows or columns of x, whichever dimension is not listed in the margin argument.

Continue reading

save, save.image, load

Save a particular set of objects using save, or save all objects in the current R session via save.image. Load an R data file into a session using load.
save(…, file)
  • – List all objects that should be saved.
  • file – Provide the file name, typically ending in .rda. Also, because the list of objects to save is arbitrarily long, the file argument must begin with the argument name, i.e. include file= in this argument’s declaration.
save.image(file)
  • file – Provide the file name, typically ending in .rda or .RData.
load(file)
  • file – The name of the file to be loaded.
In each case, the file name may also include a path to the file.

Continue reading