how to display r console in matlab - r

i am running a R script in MATLAB environment using the "system" command as described in:
How to Run a R script from Matlab
my R script takes too long to proceed. when i use the Rstudio itself, the progress is displayed in the r console. but i am not able to see the progress status in matlab screen when i call the R script from Matlab.
how can i see the progress of running the R script.
is there any command for that?

You need to specify the '-echo' option when using the system command
[status,cmdout] = system(command,'-echo')
http://nl.mathworks.com/help/matlab/ref/system.html
I've used the system function with the -echo option to run ffmpeg from the matlab command window, and the resulting command window output is the identical to what I see in the cmd.exe console.
If this doesn't resolve the issue, can you post some example code of what your doing?

Related

ProfileView plot not showing when running Julia Code

I wanted to profile my code in Julia and I installed the package "ProfileView.jl". However, when I run the code the windows is popping for a second and closing immediately.
I have run the script from VS Code and also from the terminal. The code I am profiling is:
using ProfileView
#profview Mesh,MatPointData, AnalysisConstants = setupfunc(T)
In general, you should run ProfileView interactively in a REPL, not as part of a script. If you're using VSCode, you want to start the Julia REPL (Ctrl-Shift-P and then Julia: Start REPL); from the terminal, you want to run an interactive session, i.e., $ julia and not $ julia somescript.jl.
If you simply must use a script (again, not recommended because you'll lose access to some nice interactive functionality in ProfileView), see https://juliagraphics.github.io/Gtk.jl/latest/manual/nonreplusage/.

R pop-up boxes not working when run in terminal

I am using the svDialogs (an R wrapper library for zenity) to create GUI pop-up boxes, and this works fine when I run the code through either R studio, or from an R terminal session (running Ubuntu 16.04).
A minimal example is:
library(svDialogs)
dlgMessage("Hello Stackoverflow!")
However, when I run the code directly through the terminal it does not work:
Rscript --vanilla -e 'source("path/to/file.R")'
The terminal shows that the library loaded, and does not display an error message: but the pop-up does not appear! If I add an additional line after the call to dlgMessage, that line runs. i.e. if I run the modified code
library(svDialogs)
dlgMessage("Hello Stackoverflow!")
print("Goodbye Stackoverflow!")
then the second line does show in the terminal window (i.e. the code is not crashing at dlgMessage).
Happy for solutions not relying on dlgMessage if there is a workarond: I'd previously tried using Zenity natively through R using system() but couldn't get this to work.
R can be run in either interactive or non-interactive modes, with the default depending on whether or not it is assumed that there is a human operator, see documentation for interactive.
When run in non-interactive mode, R will not display any pop-up boxes. The default is that when running code in the terminal, R runs in non-interactive mode. Following the documentation above, this can be overwritten by using the command in linux
R --vanilla --interactive < "path/to/file.R"
Similarly in Windows using --ess with Rterm.exe

Detect if R Script is Running in Interpreter or from Command Line [duplicate]

Is it possible to determine - from within the script - whether the script is running in the R-GUI (specifically R.app on OS X) or whether it has been called from Terminal/command line (i.e. R --vanilla -f script.R)? If so, how is this possible?
I'm asking because I have a script that can run parallelized (using the doMC library), which should not be used from the GUI. Sometimes I need to further process the data calculated in the script, so I'd like to call the script from the GUI on these occasions.
Perhaps you are looking for interactive()?
In C, you would use the isatty function. If you could find an equivalent function in R (probably in a UNIX or file system library), that should help.

Can I start an Rcmdr session from a unix shell?

I want to launch Rcmdr as a command from bash (or any unix shell), perhaps as an alias. R accepts the CMD argument and I could also pipe a script in with <. I would like the R console to stay open, and an interactive RCommander session to be started (Rcmdr is a popular GUI for R, for any newbies reading along, and it seems that you start up R, type library(Rcmdr) and then Commander() to start it up).
I am aware of how to add Rcmdr to my profile, and it appears to always start up if I include library(Rcmdr) in my .Rprofile, on my Linux workstation.
If I pipe my input in with < then this script works up to the point where it says that Commander GUI is launched only in interactive sessions:
library(Rcmdr);
Commander();
However if I run R CMD BATCH ./rcommander.r it just starts up and shuts down immediately, probably giving me some warning about interactive sessions that I didn't see, because CMD BATCH puts R into non-interactive mode and is thus useless for the purpose of "injecting" Rcmdr into an interactive R session.
It appears impossible to "source a file on the command line but run interactively" in R. It also appears that there are command line options to ignore the global and the user profile, but not to specify a custom profile like R --profile-custom ./.Rprofile2
Either I would like to specify a profile that means "Right now I want to start up and use RCmdr" and still be able to run R without it sometimes.
Working on an Ubuntu machine here, I was able to use the advice provided by Dirk in this mailing list post:
nathan#nathan-laptop:~/tmp$ cat rcommander.r
#!/bin/bash
r -lRcmdr -e'while(TRUE) Commander();'
nathan#nathan-laptop:~/tmp$ cat rcommander2.r
#!/bin/bash
Rscript --default-packages=Rcmdr -e 'while(TRUE) Commander();'
The first script uses Dirk's littler package, available on CRAN, and the second uses the standard Rscript executable. As noted, you can kill the process with ctrl + c from your terminal.

How to run a program in R language using terminal and to see the output

Using putty, I installed the terminal environment. Here I want to run an R program which may produce some graph or plots. What are the commands to run such a R program? What are the commands to create the directory and see the output of such a R program?
You can run your R script in batch mode.
R CMD BATCH your_script.R your_scripts_output.txt
I'm not sure that you can view plots in terminal mode. However you can save the plots to an image (png, pdf, ...)

Resources