R's subscripting operators do not "guess" the value of a missing
argument: a missing k'th subscript means seq_len(dim(x)[k]).
I bet that you use syntax like x[,1] (the entire first column of x)
all the time and that you don't want this syntax to go away.
Some languages use a placeholder like '.' o
Thanks Bill,
This is more clear.
In any case, I find very inappropriate that a programming language tries to
guess the value of a missing argument. It is unfair towards code developers
and it promotes the production of bugged piece of software.
I hope R will revise its policies sooner or later.
The "missingness" of an argument gets passed down through nested function
calls. E.g.,
fOuter <- function(x) c(outerMissing=missing(x), innerMissing=fInner(x))
fInner <- function(x) missing(x)
fInner()
#[1] TRUE
fOuter()
#outerMissing innerMissing
# TRUE TRUE
It is only
Hi Petr,
Thank you for your answer.
I'm not sure how the empty index reflects what I'm showing in my example.
If my function was
emptySubset <- function(vec) vec[]
I would then agree that this was the case. But I think it's different: I'm
specifically telling my function that it should have two
Hi
Help page for ?"[" says
An empty index selects all values: this is most often used to replace all the
entries but keep the attributes.
and actually you function construction works with empty index
> x<-c(1,2,5)
> letters[x]
[1] "a" "b" "e"
> letters[]
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i
5 matches
Mail list logo