I can't get the two elements of the vector using:



I have googled a lot but don't understand why I get just the first element.


This is the documented behavior. From Sweave manual (the emphasis is mine):

There is limited support for using the values of R objects in text chunks. Any occurrence of \Sexpr{expr } is replaced by the string resulting from coercing the value of the expression expr to a character vector; only the first element of this vector is used. E.g., 3 will be replaced by the string '3' (without any quotes).

Use [\Sexpr{paste(z, collapse=", ")}]. paste will collapse your vector into a char string, which is output by \Sexpr, so the result is [1, 2]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.