开发者

R: Two output windows?

开发者 https://www.devze.com 2023-01-23 21:20 出处:网络
How can I have two output windows on R? I\'d like to be able to get some outputs on a different window.

How can I have two output windows on R? I'd like to be able to get some outputs on a different window.

For example, I'd like to keep all my instructions on the main window. And get long outputs, such as big matrices, on a different one.

开发者_StackOverflow社区

thanks


The fix or edit command with sink might be worth looking at.

see.in.new.window<-function(x){
  #examine x in a new window
  fname<-tempfile
  sink(fname)
  cat(fname)
  sink()
  edit(file)
}

Should get you close. Using the default editor (for windows is the built in editor) should work just fine. Just know that if you are using Notepad++ with NppToR then Notepad++ will be used.

Another option is to sink output to a file and open the file in an editor that will automatically, and silently update when the file has been updated. To turn on or off sinking you probably want to alias the command.


I don't think you can do that directly.

But you can get close to that if you use a proper editor where you keep your source -- which you submit line-by-line, or region-by-region, to R. Many editors can do that, and the question of 'which editor ?' has been discussed here before.

You can then have one (or more) of these files for source(s), and one main execution window.

In Emacs/ESS, the M-x ess-rdired mode lets you browse R variables similar to how dired mode browses files and directories. Typing v for view then display them in another window. I used that just yesterday to quickly compare a bunch of data.frames from different settings.

Rcmdr also has something similar in that commands and output are split.


+1 for the editor. Emacs/ESS definitely serves the purposes, and is a stable basic editor. If you use Windows, Tinn-R is a also good one, has more functionality and is relatively easy to setup (contrary to Eclipse/StatET for example).

In Tinn-R, you can use the R-terminal, and that one will split all log messages in a different window too. Your source code is in the editor window itself, so everything is to be found in its own window.

Other ideas you find in this question.

To set up Tinn-R, make sure you follow the instructions carefully. If you can't get it work, you can contact me (e-mail address is on my profile). Be sure you use R in the SDI mode (seperate windows, see under edit > GUI preferences).


A couple of more tools for looking at output or objects without cluttering your main output include:

The View function (note uppercase V) will show you data objects such as data frames and matricies in a spreadsheet like window, you can then scroll to see the different parts. The View window can remain open while you continue to work in the main window (but note that changes to the data object will not be reflected in the View window, you need to close it and rerun the View command).

The fix and edit functions allow you to view (and edit) data and other types of objects.

The page function will show an object, how it shows it depends on your system and options set (but the default on windows GUI is to pop up another window with the object inside). You could use this along with the capture.output function.

You might also want to look at the R2HTML package, the R2wd package, or the txtStart function (and related) in the TeachingDemos package for some other ways of saving your results to other formats.


In Windows, one option if you want to work within R GUI is to keep your R code/commands/instructions in a script file and pipe these commands into the console window.

In R GUI, find the File menu and select the New Script item. This produces a new window in which you can type R commands. You can send the current line from the Script window to the console window using the Ctrl-R keyboard shortcut. If you want to send multiple lines at once, highlight the relevant lines with the mouse or keyboard and then press Ctrl-R.

You can save your script (with focus on the script window, File > Save), and load it again in a later session.

0

精彩评论

暂无评论...
验证码 换一张
取 消