knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
This package makes it easy to identify objects or object elements which store a simpler hidden type. "Hidden type" refers to a simpler type or class that we could convert an object to without losing information.
A common example is numerics stored in characters.
Additionally the functions unfactor
and make_logical
allow for the quick conversions that base R doesn't.
Let's get those out of the way first and then go through the hides_*
functions.
library(hidden)
Convert a factor or the factors of a data.frame, list or environment to the type they hide (character or numeric).
make_logical(c(0,1,2,1,2,0), na.values = 0) ## it's not safe not to mention the true and false values, here yes becomes FALSE make_logical(c("yes","no","yes","maybe"), na.values = "maybe") ## we can mention only one of the true/false values make_logical(c("yes","no","yes","maybe"), false = "no",na.values = "maybe") ## no message is displayed if both true/false values are given make_logical(c("yes","no","yes","maybe"), true = "yes", false = "no",na.values = "maybe")
Convert to logical if hides_lgl(x, ...)
is TRUE
.
unfactor(factor(c(1,2,3))) unfactor(factor(c("a","b","c"))) iris2 <- iris iris2$Sepal.Width <- factor(iris2$Sepal.Width) str(iris2) str(unfactor(iris))
TRUE
if character or factor could be converted to numeric without loss of information.
## hides_num hides_num(c("1","2",NA)) hides_num(c("1.5","2",NA)) hides_num(factor(c(1,2,NA))) hides_num(c(1, 2, NA)) hides_num(c(1.5, 2, NA)) hides_num(c(1L, 2L, NA)) hides_num(c(1, 2, NA), obvious = TRUE) hides_num(c(1.5 , 2, NA),obvious = TRUE) hides_num(c(1L,2L,NA), obvious = TRUE)
TRUE
if numeric, character or factor could be converted to integer without loss of information.
## hides_int hides_int(c("1","2",NA)) hides_int(c("1","2","a",NA),"a") hides_int(c("1.5","2",NA)) hides_int(factor(c(1,2,NA))) hides_int(c(1, 2, NA)) hides_int(c(1.5, 2, NA)) hides_int(c(1L, 2L, NA)) hides_int(c(1, 2, NA), obvious = TRUE) hides_int(c(1.5 , 2, NA),obvious = TRUE) hides_int(c(1L,2L,NA), obvious = TRUE)
TRUE
if numeric, character or factor contains binary values that
could be converted to \code{logical} without loss of information other than labels (see make_logical
).
## hides_lgl hides_lgl(c("yes","no","yes",NA)) hides_lgl(c("yes","no","yes","maybe")) hides_lgl(c("yes","no","yes","maybe"),"maybe") hides_lgl(factor(c("yes","no","yes",NA))) hides_lgl(factor(c("yes","no","yes","maybe"))) hides_lgl(factor(c("yes","no","yes","maybe")),"maybe") hides_lgl(c("1","2",NA)) hides_lgl(c("1.5","2",NA)) hides_lgl(factor(c(1,2,NA))) hides_lgl(c(1, 2, NA)) hides_lgl(c(1.5, 2, NA)) hides_lgl(c(1L, 2L, NA)) hides_lgl(c(TRUE, FALSE, NA)) hides_lgl(c(TRUE, FALSE, NA), obvious = TRUE)
TRUE
if data.frame list or environment contains only objects of length 1.
## hides_vec hides_vec(list("a","b","c")) hides_vec(list(1,2,3)) hides_vec(list("a",2,3L)) hides_vec(list(c("a","z"),"b","c")) hides_vec(c("a","b","c")) hides_vec(c("a","b","c"), obvious = TRUE)
TRUE
if list or environment contains only objects of same length.
hides_df(list(1:5,6:10)) hides_df(list(1:5,6:11)) hides_df(list(letters[1:5],6:10)) hides_df(list(letters[1:5],letters[6:10])) hides_df(iris) hides_df(as.list(iris)) hides_df(iris, obvious = TRUE)
TRUE
if data frame, list or environment contains only objects of same length and same type.
## hides_mat hides_mat(list(1:5,6:10)) hides_mat(list(1:5,6:11)) hides_mat(list(letters[1:5],6:10)) hides_mat(list(letters[1:5],letters[6:10]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.