30 agosto, 2021
is.atomic()
ou is.recursive()
# Funcao auxiliar eh_atom_ou_recur <- function(x) c(atomico = is.atomic(x), recursivo = is.recursive(x)) # Testando alguns objetos eh_atom_ou_recur(c(a = 1, d = 3)) # TRUE FALSE ## atomico recursivo ## TRUE FALSE eh_atom_ou_recur(list()) # FALSE TRUE ## atomico recursivo ## FALSE TRUE eh_atom_ou_recur(list(2)) # FALSE TRUE ## atomico recursivo ## FALSE TRUE eh_atom_ou_recur(mean) # FALSE TRUE ## atomico recursivo ## FALSE TRUE eh_atom_ou_recur(y ~ x) # FALSE TRUE ## atomico recursivo ## FALSE TRUE eh_atom_ou_recur(expression(x^2 + 2)) # FALSE TRUE ## atomico recursivo ## FALSE TRUE eh_atom_ou_recur(quote(sqrt)) # FALSE FALSE ## atomico recursivo ## FALSE FALSE
lista <- list(x = 2, y = list(z = 3)); lista
## $x ## [1] 2 ## ## $y ## $y$z ## [1] 3
fun1 <- function(x) { fun2 <- function(y) x + y fun2(x) } fun1(2)
## [1] 4
# Objeto NULL is.vector(NULL); is.atomic(NULL)
## [1] FALSE
## [1] TRUE
# Objeto com atributo x <- structure(1:10, atrib1 = "teste") is.vector(x); is.atomic(x)
## [1] FALSE
## [1] TRUE
vector(mode, length)
vector(mode = "logical", length = 5)
## [1] FALSE FALSE FALSE FALSE FALSE
vector(mode = "numeric", length = 5)
## [1] 0 0 0 0 0
vector(mode = "raw", length = 5)
## [1] 00 00 00 00 00
x <- structure(1:10, atrib1 = "atributo 1") is.atomic(x); is.vector(x); as.vector(x); attributes(x); attributes(as.vector(x))
## [1] TRUE
## [1] FALSE
## [1] 1 2 3 4 5 6 7 8 9 10
## $atrib1 ## [1] "atributo 1"
## NULL
x <- c(arg1 = 1, arg2 = 2); x; attributes(x)
## arg1 arg2 ## 1 2
## $names ## [1] "arg1" "arg2"
is.atomic(x); is.vector(x)
## [1] TRUE
## [1] TRUE
# Objeto tipo 'integer' e 'numeric' x <- 1L # Vericando is.vector(x, mode = "numeric")
## [1] TRUE
is.vector(x, mode = "integer")
## [1] TRUE
typeof(x)
## [1] "integer"
mode(x)
## [1] "numeric"
# Criando um objeto "symbol" ou "name" x <- as.vector(1, mode = "symbol") # Verificando is.vector(x, mode = "symbol")
## [1] TRUE
is.vector(x, mode = "name")
## [1] TRUE
# Criando um objeto "pairlist" fxy <- function(x, y) c(x, y) argumentos <- formals(fxy) # Verificando is.vector(argumentos, mode = "pairlist")
## [1] TRUE
mode = any
: "character"
, "integer"
, "double"
, "numeric"
, "complex"
, "raw"
, "list"
ou "expression"
# Criando um objeto "any" x <- as.vector(1, mode = "any") # Verificando o tipo is.vector(x, mode = "any"); is.vector(x, mode = "numeric") ## [1] TRUE ## [1] TRUE mode(x) ## [1] "numeric" typeof(x) ## [1] "double"