Like just about every other grad statistics student, my first 2-3 years of education in R programming was a bit disjoint. I’d pick up skills and learn new functions from random courses and sources. This post features five functions that I wish I’d known soon after I started programming in R but didn’t learn until 2 or more years in.
identical(x, y). Check if two R objects x and y are exactly identical.
txtProgressBar, setTxtProgressBar. Set the parameters of a progress bar using txtProgressBar, then print the progress bar in each iteration of a loop using setTxtProgressBar. Pretty much any for loop that takes more than five seconds to run would benefit from the use of these functions.
package.skeleton. Generate all the skeleton files for a package using the objects in an R session. I’ve taken to creating a package for most projects I work on to organize data and functions. If you aren’t familiar with package building, start by viewing this video guide.
by(data, INDICES, FUN, …). Apply a function across subsets of data, where the subsets are defined by the INDICES argument. The by function returns an object that summarizes each particular subset of the data according to the indices used.
traceback. If there’s an error returned from a function, use the traceback function to trace the last command run that caused the error.
Consider leaving your favorites in the comments!