How to create an "empty object" in R? [edit: I don’t know how to call this "thing" correctly, so I call it "empty object", others: "empty character", "zero-length character", "missing object" can also be used]
[edit2: finally, I lean toward the “missing character object” for the name “thing”. It also appears that J.Chambers uses this terminology in his 2008 book, see Comments for @mbq's answer. According to Chambers, the “missing character” has a zero-length string as content. Thus, as.symbol ("") should create an object that it does not have in the current version of R (2.11.1)]
The easiest way to find:
x <- alist(a=)$a
[Clarification]
Note that the "empty object" is not a NULL object or a vector of length 0. The "empty object" x in my example above can be used in manipulating formal forms, for which I need it.
Here is an example:
> al <- alist(a = 323, b = , c = 434) > al $a [1] 323 $b $c [1] 434 > > al[["c"]] <- numeric() > al $a [1] 323 $b $c
So, I'm just looking for a way to create empty objects for use in manipulating formal forms. I am sure that there should be a way in the R. database.
Here is an example:
> foo <- function(a = 3232, b = 234){b+a} > formals(foo) $a [1] 3232 $b [1] 234 > formals(foo)$c <- alist(a = )$a > formals(foo) $a [1] 3232 $b [1] 234 $c > foo <- function(a = 3232, b = 234){b+a} > formals(foo) $a [1] 3232 $b [1] 234 > formals(foo)$c <- alist(a = )$a > formals(foo) $a [1] 3232 $b [1] 234 $c
Thanks.
r
VitoshKa
source share