findFn (sos package)

findFn(string, maxPages = 20)
Do a search for functions, which opens an interactive HTML page of results. The results may be sorted in a variety of ways and also link to help files for each function. The results page will automatically open in whatever application has been designated to open .html files (usually a browser is the default).
  • string – A character string to search.
  • maxPages – Maximum number of pages to return, i.e. number of links is 20*maxPages.

Continue reading

with, within

with(data, expr)
within(data, expr)
Perform R expressions using the items (variables) contained in a list or data frame. The within function will even keep track of changes made, including adding or deleting elements, and return a new object with these revised contents.
  • data – Typically a list or data frame, although other options exist for with.
  • expr – One or more expressions to evaluate using the contents of data (which are accessed directly), where the commands must be wrapped in braces if there is more than one expression to evaluate.

Continue reading

as.Date, strptime

Format dates using the as.Date, or format dates with times using strptime. There are helpful defaults for as.Date.
as.Date(x, format="%Y-%m-%d")
  • x – A character vector of dates.
  • format – The format of the dates, using a percent symbols with characters to specify what types of date information can be found where. By default, the function will accept dates of the form "2012-02-26" or "2012/02/26", but this can be adjusted for other scenarios.
strptime(x, format)
  • x – A character vector of dates, possibly also including times.
  • format – The format of the dates, using a percent symbols with characters to specify what types of date and time information can be found where. See ?strptime for all of these character options and meanings.
For a complete list of the date/time specification options, see the help file for strptime.

Continue reading

debug, undebug

Use debug to put a function into debugging mode. When a function is in debugging mode, the function’s commands are run one at a time, and the function only moves onto the next command when told to do so. Between each of these function commands, the variables within the function are accessible and other commands may be run, making it easy to check the values of variables, change those values, or run other commands. To take a function out of debugging mode, use the undebug function.
debug(fun)
  • fun – A function.
undebug(fun)
  • fun – A function.

Continue reading

TRUE and FALSE, not T and F

TRUE != T, FALSE != F
It is common to see code that uses T for TRUE and F for FALSE, but this can lead to unexpected errors. By default, R assumes T and F are TRUE and FALSE. However, these variables are sometimes overwritten, whereas TRUE and FALSE cannot be overwritten. For example, T is occasionally used for a time variable by users; if the first element of T is zero, then there can be serious consequences.
This issue is so severely overlooked that it is common to read a textbook highlighting the use of R and see inappropriate use of T and F.

Continue reading