Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Would it be better if knitr DID NOT enclose the result of inline commands in R Markdown files with backticks? #244

Closed
jeromyanglim opened this Issue · 4 comments

3 participants

@jeromyanglim

Currently, knitr converts

`r 2 + 2`

into

 `4`

and the Markdown converter then generates

<code>4</code>

However, I think it would be better default behaviour to just print the result, WITHOUT enclosing the result in backticks (which are in turn converted to code tags).

  • If I don't want the code tags, I have no choice. Whereas if the default behaviour was to not add TAGS, I could just add the tags.
  • I don't think Sexpr adds any formatting. And this is the behaviour that I would expect.
  • In particular, I was trying to write a formula in a blog post that included inline output. However, this didn't work because of the code tags (e.g., $2+2 = r 2 + 2$).
  • Keeping it plain gives the user freedom to do what they want with the resulting output.

Alternative, is there a way of using handles or some other feature to disable the use of <code> tags for inline code in R Markdown?

@ramnathv

I don't think knitr is adding this markup. I believe it must be markdown, which is translating inline to code. AFAIK, markdown was not designed for reproducible document writing. So the inline usage was mainly to highlight code, which is why you are seeing the markup.

@jeromyanglim

@ramnathv I updated the issue to clarify my understanding of the role of knitr and the markdown to html program. I'm essentially asking whether the default behaviour in knitr for inline commands should be to just print the result rather than surrounding the result in backticks. I think this would be more flexible.

Also, I imagine you have not seen what R Markdown can do. It supports inline commands now. See the answer to this question.

@yihui
Owner

sorry, this is not well documented; the solution is to use I(), which means not to wrap my result in any tags; just leave it as-is, e.g. I(2+2)

it is hidden deep in https://github.com/yihui/knitr/blob/master/R/hooks-md.R#L38

@jeromyanglim jeromyanglim reopened this
@jeromyanglim

Thanks @yihui . That works perfectly. I added the details to this question on stack overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.