I use elipsis because I want to use a varying number of variables in my function. I cannot seem to call the individual elements in a loop and use them in simple mathematical operations.
tst <- function(...) {
print(..1)
q = 1 + ..1
print(q)
for (i in 1:3) {
val <- get(paste0("..", i))
print(val)
s = 1 + val
}
}
If I run tst(1, 3, 4)
I expect to get output like
[1] 1
[1] 2
[1] 1
[1] 3
[1] 4
Instead I get
[1] 1
Error in get(paste0("..", i)) : object '..1' not found
This tells me that outside the loop, the ..1
is recognized as a numeric object, and yet inside the loop it cannot find it.