How to refresh plots without needing to close the previous plot? - r

How do I get VSCode to refresh the plot when making a new plot without needing to close the previous plot tab?
Ideally, it should open up a new tab with the new plot next to the old one.
Moreover, when using Httpgd, even tho the plot refreshes without me having to close the previous plot, it opens up in a separate window outside VSCode. How do I get it to open up as a new tab like in the gif above?

I had the exact same problem and what fixed it for me was simply, in vscode, going into:
Files > Preferences > Settings > section Extensions > scroll down and find R:
find the section "Plot: Use Httpgd" and check it, and restart Vscode.
I can't confirm but I believe it might have started after installing the httpgd package, because I had the behavior you desire before installation, and the exact same behavior you experience after httpgd installation. Of course if my solution works for you (I hope), it will work under httpgd after and not the base default VsCode/R-plot viewer as in your gif.

#coip pointed out that the steps given on this stackoverflow post to me. Downloading the httpgd package from CRAN fixed the problem for me.

Related

Setting up R in Atom: How to Run a Help Page

I successfully set up R in my new Atom editor and can get in-line results using the Hydrogen package. I just noticed, however, that when I run lines to obtain "R Documentation" that would pop up automatically in RStudio, Hydrogen only gives me a check mark in-line result with no associated documentation.
Here is what is going on in my Atom editor when I run ?plot
Here is what happens in RStudio (bottom right pane), which I am hoping I can get in Atom
How can I get this working in Atom?
try hydrogen -> Toggle inspector
I had the same question and actually made a little progress. Perhaps someone more experienced than I can use this to make a package to enable an in-atom help documentation panel for us :)
Anyway you can install the atom package 'script' which will properly output some, but not all, help documents. I have an example of one working & one not working.
Working ?read.csv
Not-working ?geom_bar

How to open the viewer pane in browser?

Just a simple question that I couldn't find an answer. I just updated my R Studio and R, and one function that I used a lot was opening the results in Viewer pane in my browser.
For example, with the resulting tables from packages like sjPlot or expss, I used the "Show in new window" to visualize the tables in Chrome or other default browser. Don't know if this was set by a old package, but I can't get this result right now. Actually, when I click this option, nothing is happening.
When I change to my old R version 3.6.2, I can use the "show in new window", but can't make to work in the version 4.0.1.
Anyone would know how can I get this function again?
Thanks
options(viewr=NULL) should do the trick.
In my case, i use browseURL instead of rstudioapi::viewer open file in browser directly.
browseURL(sprintf("%s/test.html", tempdir()))
if your file not in tempdir(), you should copy it to tempdir() first:
system(sprintf("cp %s %s", test_file, tempdir()))

r plot shows up only when I type in console but not in script

I ran into a very weird problem: my R code for generating a plot only works if I type it into the console but not when I ran it inside the script (with Ctrl+Enter command)... It's the same problem with all plots (regular plots or ggplots). Also I tried it on two different computers and the same thing happened. Anyone have any idea why this is happening?
One possible reason: I installed the newest version of Rstudio on both computers so it might be an issue with the version. The exact same code worked before on an older version of rstudio...Could this be it? If so, how can I fix it?
I think I figured out what the problem was: the setting in the new version of Rstudio has a default option of outputting the plots inside the Rmarkdown script (at the very end of the script). And that's why I wasn't seeing them. You could change the setting such that it outputs in the console.
Try dev.off() to reset the graphics device.
This helps with a lot of weird graphics behaviour.
Probably too late for the original poster... However, I just ran into the same problem after installing an R update. The way I fixed it was to go to preferences, R markdown, and turn off "show inline output". For me, it was just coming out at the bottom of the chunk instead of in the plot window like I wanted. Hope that helps someone!
I just ran into this problem. I mistakenly put my plot() command inside the r markdown setup chunk. I moved it to its own code chunk and it ran as expected.

ggplot2 library installation in R Studio

New to R Studio and wondering to install new package like ggplot2 (or any other additional packages/libraries), any convenient ways? Thanks.
regards,
Lin
You can do what Heroka said, which is the quickest way, except that you have to know the exact name of the package you want to install.
The other way is to go to the bottom right quadrant and select the "packages" tab and click on "install packages" above the list. This will open a new window where you will select what package you want to install, where on your system and from where. Also, there's auto-completion, so you just have to enter the first letters and select which package you want.
The advantage to doing things in script (library(ggplot2)) is that loading a package can be saved at the top of the script and easily run every time you run a script. Clicking cannot be saved, and must be done manually every time.
Use install.packages(ggplot2) in the console of RStudio or another GUI and then load the package using library(ggplot2) afterwards. If you don't get any errors you're good to go

How can I get a plot window in RStudio?

I am able to run the plot command successfully but not able to view the graph/chart window in RStudio. I can save it using "dev.off" command in my hard disk and then open it. I have checked all the options in the GUI but did not find it. I wonder if there is any package to be installed. Please suggest.
Have you tried checking if the Plots tab is enabled in the global options panel?
Click "Tools" > "Global Options" and then go to "Pane Layout." The "Plots" tab should be present and enabled in one of your panes as shown below:
I often have this problem. I do not know why, but quitting and restarting R usually solves it for me.

Resources