Create or test for objects of type "integer".
This function is a wrapper of the function as.integer()
and evaluates
if the object to be coerced can be interpreted as a integer. Any object :
NA, NA_integer, NA_Date_, (...),
Boolean, such as 0, 0L, F, FALSE, false, FaLsE, (...),
Any string "1", "+1", "-1", "1.0000"
will be converted as NA or integer. Any other other will return an
error.
as_any_integer(x)
Object to be coerced or tested. Can be a vector.
An integer object of the same size.
{
library(dplyr)
as_any_integer("1")
as_any_integer(c("1.000","2.0","1","+12","-12"))
try(as_any_integer('foo'))
tibble(values = c("1.000","2.0","1","+12","-12")) %>%
mutate(bool_values = as_any_integer(values))
}
#> Error : x is not in a standard unambiguous format to be coerced into type 'integer'
#> # A tibble: 5 × 2
#> values bool_values
#> <chr> <int>
#> 1 1.000 1
#> 2 2.0 2
#> 3 1 1
#> 4 +12 12
#> 5 -12 -12