R has several built-in NA values that correspond to the atomic data types, such as NA (logical), NA_integer_ and NA_character_. Calling use_na() allows the programmer to have NA values of any class. In addition, use_na() provides several useful NA values such as NA_list_, NA_Date_ and NA_POSIXct_.

use_na(path = "R", export = TRUE)

Arguments

path

(character) A path pointing at where to copy the file.

export

If TRUE, the file content is exported to NAMESPACE.

Value

No return value, called for side effects.

Details

The function copies a file with several NA values to 'path/utils-na.R'.

Examples

path <- tempfile() use_na(path) print(readLines(file.path(path, "utils-na.R")))
#> [1] "#' @title Various 'Not Available' / Missing Values" #> [2] "#' @description R comes with several built-in NA constants, including `NA`" #> [3] "#' (logical), `NA_integer_`, `NA_real_`, `NA_complex_` and `NA_character_`." #> [4] "#' Similarly, we can define NA values that are associated with other classes," #> [5] "#' such as, `NA_Date_` and `NA_list_`." #> [6] "#' @name na_utiles" #> [7] "#' @return Predefined constant." #> [8] "NULL" #> [9] "" #> [10] "" #> [11] "# Atoms -------------------------------------------------------------------" #> [12] "#' @rdname na_utiles" #> [13] "#' @export" #> [14] "NA_numeric_ <- structure(NA_real_, class = c(\"integer\", \"numeric\"))" #> [15] "" #> [16] "" #> [17] "# Timedate ----------------------------------------------------------------" #> [18] "#' @rdname na_utiles" #> [19] "#' @export" #> [20] "NA_Date_ <- structure(NA_real_, class = \"Date\")" #> [21] "#' @rdname na_utiles" #> [22] "#' @export" #> [23] "NA_POSIXct_ <- structure(.POSIXct(NA_real_, tz = \"UTC\"), class = c(\"POSIXct\", \"POSIXt\"))" #> [24] "" #> [25] "" #> [26] "# Arrays ------------------------------------------------------------------" #> [27] "#' @rdname na_utiles" #> [28] "#' @export" #> [29] "NA_list_ <- structure(list(), class = \"list\")" #> [30] "#' @rdname na_utiles" #> [31] "#' @export" #> [32] "NA_data.frame_ <- structure(data.frame(), class = \"data.frame\")"