R ooutput in markdown documents


#1

Hello. I’m using Atom as my R coding platform, because it offers the best voice-coding integration/support. I’m following along with an online course, and I have found all the workarounds/packages, I need to do this lesson entirely in Atom, except for the last step. When I output the R markdown document, I get the R code I put in, instead of the output for that R code (tables and figures). In the raw markdown document, I can successfully run the code and get the appropriate output using a Hydrogen/Rbox set up, but the graphs and figures don’t display in the preview, or the created HTML or PDF file. There seems to be some discussion around this from 2016,and I’ve explored the following resources.

  1. Old discussion thread
  2. The 2016 article, The current state of R support in Atom
  3. An apparently defunct Rmarkdown grammar on GitHub
    However, Atom, it’s packages, and R integration, seem to have come a long way since 2016. Have I missed something simple, or is there still no straightforward way to integrate graphs and tables from R into markdown documents within Atom?

#2

What package are you using to output the R markdown document?


#3

Thanks for the speedy reply. When outputting as HTML, I was using “markdown preview” then creating the file from the from the right-click menu within the preview, by selecting save as HTML. The PDF process was quite a bit simpler, and use the package “markdown to PDF”. In that case, it’s a single click in the packages menu.


#4

The core package markdown-preview has no awareness of non-markdown code as far as I know.


#5

Okay, I think you’re right about that. I looked through all my markdown associated packages last night, and it looks like the only one that explicitly says it’s aware of Rmd files is language-markdown. I also tried to use markdown-img-paste to add JPEG images of my graphs to my markdown, had the same problem, the code to insert the image appears in the final PDF or HTML file, but not the actual image. I also tried to do the same thing using markdown-writer and it’s associated toolbar. No luck with that approach either. Any thoughts?


#6

I would have to see the code to tell you why that happens.

Any thoughts?

Yes, that your workflow is an edge case not well-supported by the packages out there. If you can direct me to an open-source library that you would use to convert R code to markdown (I know nothing about this, so you’re the expert here), I can give you guidance on how to make Atom do what you want it to do.


#7

Thanks for your patience, being a newbie with an edge case workflow is intimidating to say the least. I actually did find a workaround. If you have language-markdown, markdown-writer, and tool-bar-markdown-writer installed, then, you can install open-in, and add Rstudio to the application list. Except, the instructions in the readme don’t actually work, use bastiMQ’s here instead. Once you’ve done that, it’s straightforward, you can open the Rmd file that you created in Atom with Rstudio, and produce a properly formatted HTML markdown document with your tables and figures with one click, once Rstudio is open. If you want PDF support on Windows, you’re going to need to install the full version of miktex via the net installer. I’d link to it here, but I think I met my link limit for this post. (Fair warning, the download/install process for miktex is straightforward, but you’re going to want to block out a chunk of time, because the tool downloads and installs over 2.5 GB of files.) Now that I’ve got the hard part figured out, I’m having a total newbie problem, I can’t seem to change the key binding to toggle open-in. The default <control alt + o> conflicts with a hydrogen function, so I’d like to set it to the same binding using the number “0” instead of the letter “o”, but I can’t seem to get it working. I’ve unchecked the appropriate checkbox in open-in -> settings and added the following to my keymap with no effect.
# trying to add Key binding for open-in
‘.atom-workspace’:
‘ctrl-alt-0’: ‘open-in:toggle’
Everything works if I scroll through my giant packages menu and physically click toggle, but a functioning key binding would be much more efficient. What mistakes am I making with the key bindings? I’ve read the relevant flight manual section, but I always seem to have problems when editing key bindings.


#8

atom-workspace is a tag name, not a class name, so the . is what’s breaking it. Keybinding selectors are designed to imitate CSS.

Additionally: when posting code, make sure to highlight it and press the </> button above the editor. CSON is indentation-specific, and without the preformatting tags I can’t tell if you’ve written it correctly.


#10

Thanks! That worked.
Trying to post the corrected code, using the preformatted text button gives me two options, neither of which will correct.
either I get

trying to add Key binding for open-in

‘atom-workspace’:
‘ctrl-alt-0’: ‘open-in:toggle’
or
# trying to add Key binding for open-in
‘atom-workspace’:
‘ctrl-alt-0’: ‘open-in:toggle’


#11

It works for me.

That’s the simplistic way. The nicer-looking way uses backticks.


#12

Nice video clip, that’s exactly what I was doing, but I wasn’t getting that result. I actually just used the second method you demonstrated, in a reply to the thread I referenced at the top of this one, and it worked great. Thanks.