4

The R documentation says

is.atomic returns TRUE if x is of an atomic type (or NULL) and FALSE otherwise.

is.recursive returns TRUE if x has a recursive (list-like) structure and FALSE otherwise.

is.atomic is true for the atomic types ("logical", "integer", "numeric", "complex", "character" and "raw") and NULL.

Most types of objects are regarded as recursive, except for the atomic types, NULL and symbols (as given by as.name).

According to the above, I thought a vector is a recursive object, but the two functions show the opposite.

Also a function (like c) is also a recursive object

So what are the definitions of recursive objects and of atomic objects in R?

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • Why would you think vectors are recursive? The examples in the link you provided include calling `is.atomic` and `is.recursive` on a vector, with results `TRUE` and `FALSE`, respectively. – Joshua Ulrich Mar 16 '14 at 20:26

2 Answers2

11

Being recursive for a type of object in R means that you can have this object holding its own type as an entry. Atomic is the opposite. Vectors are atomic and lists are recursive as you can easily check.

An atomic structure, like a vector, will have a flat structure. The following codes for instance will lead to the same result:

c(1,2)
c(1, c(2))

also all elements in a vector will have the same type

c(1, 'a')

will force 1 as character

A list on the the other hand can have a nested structure, for instance

list(1, list(2, 3))

bendaizer
  • 1,235
  • 9
  • 18
0

according to my understanding, and correct me if i'm wrong, recursive argument is used where theres a nested directory. E.g if i had to create a directory 'dir1' with its own sub directory 'dir2' i would use the recursive argument

dir.create(file.path("dir1", "dir2"), recursive = TRUE)

likewise, you use the recursive argument when deleting directories and all their contents as confirmation that you are aware that you are performing that task.

unlink("dir2", recursive = TRUE)