Is there some function to clear all viewer iterms in RStudio? so I donot need to clear manually.
Not an R function but a Mozilla hotkey:
CTRL + Shift + W
It will prompt you to save scripts, though.
Related
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()))
I'm starting learning R with coursera.org. I've chosen Eclipse Java Neon with StatET plugin as editor and here is my question. Is any more efficient way to loading file to R console instead writing source("file.R") after every change in this file? I mean about something like "Source on save" in RStudio.
Running R documents
What I use the most is simply selecting in the window the part I want to run and run
Ctrl+R Ctrl+R
if I want to run the whole file
CtrlA+ Ctrl+R Ctrl+R
if I want to run the R script by submitting directly
Crtl R + Ctrl D
or
right click in the document, run as
If I want to save the file first Ctrl+S
you can also use the buttons in the toolbar at the top, they will let you learn the shortcuts.
If you prefer different shortcuts.
Window>Preference>General>Keys and edit the shortcuts you want to have.
Is there a way to simulate Alt + Tab in R?
I've been looking for functions like SendInput, keybd_event, SendMessage and SendKeys.Send but couldn't find anything similar for R.
Some context:
I am using Rscript to plot and image that appears on the graphics device windows, then I call a function similar to readLines() and R waits for my input. The problem is that after the image pops up I have to go back to the terminal in order to give input and this makes my script less efficient.
I am using Ubuntu - Unity.
EDIT:
Is it possible to call bash from R? Maybe there is a function in bash that will make this possible?
If you are on windows, the following will work:
cls <- function () {
require(RDCOMClient)
wsh <- COMCreate("Wscript.Shell")
wsh$SendKeys("%{TAB}")
invisible(wsh)
}
cls()
Taken from here: http://r.789695.n4.nabble.com/clear-screen-td884932.html
More key presses can be found here: https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
I've written quite a large R script (1000+ lines). Currently there is a rm(list=ls()) statement at the top of the script, as I need to test how it runs cleanly.
I run the code by ctrl + A, ctrl + R
The problem is is that this seems to take a long time in the Rgui to write each line to the console before running it. I feel R should be able to write to the the console faster than this and was wondering if there is a faster way to run a script.
(ie hide the lines written to the console and just run the script)
Best way is to simply source the document. If you have it saved then just type source("FullPathOfmyfile.R") and it will run without printing the commands, it will only print the output and print statements. Alternatively you can set echo = FALSE.
I input something into the R console:
> ta <- function(x,y){
+ x=x+2
+ y=y+1
+
Now my cursor is on the fourth line, I found it's x=x+1, not x=x+2.
Can I move my cursor onto the second line to revise x=x+2 into x=x+1?
As far as I'm aware, you can't do what you describe. What you can do is press Esc to cancel entering into the console and start afresh writing it in.
Are you using an IDE? Or are you writing directly into the RGui? If the latter, I heartily recommend using RStudio. It will make your life a lot easier. You'll be able to to enter text into one window and then send it into the R console when you're ready.
Alternatively. R does have an editor (File > New script) which you can use to send lines, or you can even use a txt file off to the side and only send lines when you're ready.
AFAIK, there is no way to edit the function while R is still waiting for you to close the function call. So first, I think you need to finish writing your function by typing }. Once completed, you can then do one of a few things, all of which are outlined in good detail here. I won't bother regurgitating those perfectly good answers, but do recommend you check them out. Finally, if you aren't currently using an IDE to help develop your R code, that will make your life much easier. Which IDE will be best for you is also quite subjective, but has been covered on SO here before. FWIW, I've had good luck with RStudio which is platform independent and all that good jazz...your miles may vary.
If you are running R from a terminal, you can press ctrl + c to cancel your entry and start over.