Here is a silly (maybe only in my mind) way to accomplish my goal:
A <- "This is a test."
B <- "This is the answer."
swap <- function(item1,item2) {
tmp <- item2
item2 <- item1
item1 <- tmp
return(list(item1,item2))
}
AB <- swap(A,B)
A <- AB[[1]]
B <- AB[[2]]
But I'm considering something similar to the C code following:
void swap(int *a, int *b)
{
int iTemp ;
iTemp = *a;
*a = *b;
*b = iTemp;
}
My motivations:
- My real data is quite large, e.g. 5k*5k matrix, so the assignment of the existing variable in the iteration twice, inside the function and outside the function, must be time squandering.
- The closest question on the SO is this one, but just like the OP in the question, my R session also has lots of objects: I'm working with
Rmpi
, and each slave will have a great number of variables. - In my humble opinion,
R
is written inC
, soR
may have pointers likeC
does, while I can't find much on the net surprisingly.