Does anyone know how $ is interpreted within an inline call to rscript?
In the example below, I am trying to get z to be the "a" element within the x list. However, z=x$a gives me x instead of the element of the list.
> Rscript -e "x = list(a=c(1,2,3), b=c(4,5,6)); z = x$a; print(z); print(\"z$a\")"
$a
[1] 1 2 3
$b
[1] 4 5 6
[1] "z"
Notice that even in the print statement, the $ causes somewhat obscure behavior. I would have expected this to print z$a, but it prints z instead.
Two questions:
- How exactly is "$" interpreted within a string used as inline code to Rscript?
- How can I refer to an element in a list within inline code passed to rscript?