Create the "missing objects" (aka: "empty characters", "empty objects") / necessary for processing formats /

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 #not empty numeric(0) > > al[["c"]] <- list() > al $a [1] 323 $b $c #not empty list() > > > al[["c"]] <- NULL #object removed > al $a [1] 323 $b > > al[["c"]] <- alist(a = )$a > al $a [1] 323 $b $c #empty 

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.

+6
r
source share
7 answers

Try substitute() :

 foo <- function(a = 3232, b = 234) {} formals(foo)$c <- substitute() foo # function (a = 3232, b = 234, c) 
+9
source share

What you did with alist(a=)$a is not an empty object, it is an empty character / name ('' compiled as a symbol name). I am sure that it cannot be replicated in any other way ( as.symbol('') causes an error).

+4
source share

As others have said, you are not creating an empty object. x contains a value, which is an invaluable expression.

?alist says:

'alist treats its arguments as if they were describing the arguments of a function. Thus, values ​​are not evaluated, and tagged arguments without a value are allowed, while the list simply ignores them. 'Alist is most often used in conjunction with forms.

This is the easiest way to determine whether to add an argument without a function value:

 > foo <- function(a = 3232, b = 234){b+a} > formals(foo) <- c(formals(foo),alist(c=)) > formals(foo) $a [1] 3232 $b [1] 234 $c 
+3
source share

Depending on the type:

 x <- list() # empty vectors y <- numeric(0) z <- logical(0) ... 

Now you need to think about whether you really want to create an empty object.

edit: You really can use the NULL option. The main difference is that the NULL object has no type. See Also ?"NULL"

+2
source share

There is no "empty object". There are NULL, NA (in different versions), lists of zero length, and so on. Where does your concept of "empty object" come from and what are the properties of an "empty object"?

What you created with alist is a monster:

 > x<-alist(a=)$a > x Error: argument "x" is missing, with no default 

[its some indefinite function of the function argument expression. Not an “empty object” in any sense of the word that I know]

+1
source share

Also d <- c()

0
source share

Also d <- ""

(padding to fill)

0
source share

All Articles