Anti
Anti

Reputation: 397

R knitr - Show value of numeric variable in output, not variable name

In my knitr document I create a vector, which contains a single number, e.g.

x <- 25

Later on I'd like to use this number in a chunk for some calculations:

sqrt(x)

When I now create a pdf document, it will show sqrt(x). However, I'd like to make it showing sqrt(25) instead, i.e. I'd like to force knitr to output the content of x instead of the vector name (x) itself. How can this be done? Thanks a lot in advance!

Upvotes: 0

Views: 59

Answers (1)

GitZine
GitZine

Reputation: 475

if your problem is just the visualisation, so the sqrt(x) doesn't actually calculate anything, then I think the following will work: sqrt(`r x`). So the `r x` will show the value that is stored in x.

Upvotes: 1

Related Questions