Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 May 19, 2012 · 5 comments
Labels
next Issues/PRs considered for the next release
Milestone

Comments

@jeromyanglim
Copy link

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
Copy link
Contributor

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
Copy link
Author

@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
Copy link
Owner

yihui commented May 21, 2012

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
Copy link
Author

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

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
next Issues/PRs considered for the next release
Projects
None yet
Development

No branches or pull requests

3 participants