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

cat

cat(…, file=””, sep=” “, append=FALSE)
Print output to the screen or to a file. Use cat to print information to an end-user from a function. cat is also useful for writing information that is being processed or generated, one or more lines at a time, to a file.
  • – The information to be printed to the screen or saved to a file.
  • file – An optional argument that specifies a file to be created, overwritten, or appended.
  • sep – Specifies what separates the objects in that are to be printed.
  • append – If a file is specified, then indicate whether to append to the content in the existing file (the default is not to append, which means to overwrite the existing content).

Continue reading

getForm, postForm (RCurl package)

The getForm and postForm functions from the RCurl package can be used to submit forms from R. The GET and POST methods for form submission are similar but meaningfully different; check the <form> tag in the HTML of a form to determine which function to use. In the right circumstances, these functions can be useful for automating retrieval of data sets that might otherwise require a form submission for each data set.
getForm(url, …)
  • url – A character string of a URL.
  • – The GET names and their values.
postForm(url, …)
  • url – A character string of a URL.
  • – The POST names and their values.

Continue reading

rgb

rgb(red, green, blue, alpha)
Specify the amount of red, green, and blue for a color in a plot, and add transparency using the alpha level.
  • red – A number (or vector of numbers) between 0 and 1, where higher numbers mean more red.
  • green – A number (or vector of numbers) between 0 and 1, where higher numbers mean more green.
  • blue – A number (or vector of numbers) between 0 and 1, where higher numbers mean more blue.
  • alpha – A number (or vector of numbers) between 0 and 1, where 0 is fully transparent and 1 is opaque.

Continue reading

getURL, getURLContent (RCurl package)

getURL(url), getURLContent(url)
The getURL and getURLContent functions from the RCurl package are used to retrieve the source of a webpage, which is especially useful for retrieving pages for data processing (i.e. scraping). The getURLContent function is a little more robust, but the getURL function is usually sufficient.
  • url – A character string of a URL.

Continue reading

regexpr, gregexpr

The regexpr function is used to identify where a pattern is within a character vector, where each element is searched separately. The gregexpr function does the same thing, except that its returned object is a list rather than a vector. The functions return information sufficient to extract the pattern, unless the pattern is not found, then they return -1.
regexpr(pattern, text, ignore.case=FALSE)
  • pattern – A regular expressions pattern.
  • text – The character vector to be searched, where each element is searched separately.
  • ignore.case – Whether to ignore case in the search.
gregexpr(pattern, text, ignore.case=FALSE)
  • pattern – A regular expressions pattern.
  • text – The character vector to be searched, where each element is searched separately.
  • ignore.case – Whether to ignore case in the search.

Continue reading

substr, substring

Retrieve or replace a substring of a character string via the substr and substring functions. Additionally, these functions can be used to overwrite a part of a character string.
substr(x, start, stop)
  • x – A character string.
  • start – If the characters of x were numbered, then the number of the first character to be returned (or overwritten).
  • stop – The number of the last character to be returned (or overwritten).
substring(x, first, last=1000000)
  • x – A character string.
  • first – If the characters of x were numbered, then the number of the first character to be returned (or overwritten).
  • last – The number of the last character to be returned (or overwritten), which is defaulted to 1 million.

Continue reading