Learn R Programming

wikipediatrend (version 2.1.6)

wp_date: Package specific 'as.Date()' function

Description

wp_date() provides a generic function and several methods to transform something into a date, just like as.Date() from the base package. While most methods were copied 1:1 from as.Date() some changes were made that alter the usual behavior: (1) Whenever wp_date() is applied to an empty string "" or any other not-standard-unambiguous format the function will return NA and throw out a warning instead of simply kill itself with an error. (2) Whenever, as.Date usually is in the need of an origin supplied and does not get one wp_date() will assume the origin to be "1970-01-01" and throw an error instead of kill itself with an error. All these changes are made with the special purpose to make wp_trend() also with dirty, unreasonable data (e.g. "" or "2012-13-01" or "2012-02-32") and are not recommended for any other than wikipediatrend internal use.

Usage

wp_date(x, ...)

# S3 method for character wp_date(x, format = "", ...)

# S3 method for default wp_date(x, ...)

# S3 method for numeric wp_date(x, origin, ...)

# S3 method for dates wp_date(x, ...)

# S3 method for factor wp_date(x, ...)

# S3 method for POSIXct wp_date(x, tz = "UTC", ...)

# S3 method for POSIXlt wp_date(x, ...)

Arguments

x

See ?as.Date

...

See ?as.Date

format

See ?as.Date

origin

See ?as.Date

tz

See ?as.Date

Methods (by class)

  • character: Difference to as.Date.character(): Failing to parse the date, wp_date() will give return a warning and NA instead of killing itself with an error.

  • default: same as as.Date()

  • numeric: Difference to as.Date.character(): Whenever an origin is needed but not supplied instead of breaking, wp_date() will raise a warning and proceed by assuming "1970-01-01" to be the origin instead of killing itself with an error.

  • dates: same as as.Date()

  • factor: same as as.Date()

  • POSIXct: same as as.Date()

  • POSIXlt: using as.Date()