1

I am using bookdown, and calling read_chunks to load various R chunks from a separate file for execution within bookdown. This works very nicely for chunks of R activity - graphs, tables, models, etc. However, I sometimes want to use a single value in-line, such as "This dataset had N rows."

I know how to do this in a notebook, but how to do it in the context of bookdown and read_chunks is not clear. Did I miss something in the manual?

user2292410
  • 447
  • 4
  • 13
  • This dataset had \`r N\` rows – ekstroem Jul 17 '17 at 16:55
  • It's always easier to help with a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). What exactly did you try? What was the result you got vs what you wanted? – MrFlick Jul 17 '17 at 16:56

1 Answers1

0

User error is to blame here.

When I tried r print(X) I got no value back in the html output, and no error, but r X worked just fine.

So, to reiterate, inline code of the form r RCODE works fine within Rmd files rendered by bookdown. Objects defined in chunks are returned to the calling environment and thus can be addressed and used in-line in the Rmd file.

Why r print(X) did not work, but r x did, I leave to others.

user2292410
  • 447
  • 4
  • 13
  • It would depend on what `X` is exactly. `print()` is a generic function and will do different things based on the class of the object you pass to it. – MrFlick Jul 17 '17 at 19:37