I have been enjoying using R Markdown since learning R a couple years ago without any problem. But recently when running a code chunk for plotting, the plot was rendered in the Plots pane, and when for showing a table was rendered in the Viewer pane rather than the default inline which displays the chunk output right below the chunk. Does anybody have ideas why this happens? If so, how to fix it? Thanks in advance for your help!
There is a setting that controls this behavior! In the top bar of your viewer, there should be a settings icon. Click on that, and you will see many options to control the output view. Make sure you have selected "Chunk Output Inline" and "Preview in Window".
Thanks much, @arisp99 , I checked the setting and they were ticked as you mentioned (I understand those are the default and I haven't modified them), but the output remains in the Plots pane, as shown below:
I'm wondering what else can cause RStudio to change the R Markdown output behaviour like this?
The only other things I can think of are checking the Global or project settings.
Tools > Global Options
Tools > Project Options
The global options and project options both have some settings which control RMarkdown outputs. Screenshot of the global options pane:
You can also try adding this to your yaml heading (at the top of the rmarkdown document):
editor_options: chunk_output_type: inline
If all else fails and your global options are set up to show tables and plots inline, a restart of RStudio may somehow magically fix the issue.
Thanks again, @arisp99 , for such a variety of suggestions, which really help in my using of RStudio, even though I tried all of them but still failed.
Strangely, I tried to shorten the filename (i.e. 06-Non.Rmd) and then it behaved as normal as shown below:
But after the filename was changed back to the original, the same problem appeared. I was wondering does the filename length (perhaps including path length) affect the behaviour of the output? I noticed in generating a plot some temporary files were generated and occasionally I got an error saying "unable to start png() device" or something like "the temporary file name is too long."
That's interesting. You might be on to something with file name length. It seems as though Windows and Linux both have maximum path/filename lengths (see this stack overflow question). If you are using Windows, this might explain it!
This must be it — (filename + file path) is too long! My file was originally on OneDrive which has a bit of nesting already, even though it seemed still under 255 characters (~ 200). After copying my work files to local drive with a path length of 32 and re-running the files, all of my miseries were gone! All the tables and plots appeared where they supposed to be, even some junk warnings disappeared. The only bit of inconvenience may be that we are confined to work with short-enough names for both files and paths.
Thanks a lot for your insightful help, @arisp99! I hope the long-name problem could be solved someday through either the Windows or RStudio.
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.