Error during initialization gnuplot with cygwin (terminal wxt) - initialization

I get an error, when I try to start gnuplot via cygwin (see below): Gnuplot does not seem to know the wxt-term, but according to this page (https://cygwin.com/pipermail/cygwin-announce/2020-July/009620.html), gnuplot should be able to know it.
After this I can use gnuplot by hand, e.g. typing in comments and it works normal.
But usually a have automatic plot programs and the error will cause the program to crash, so I can't work with it properly.
Is there any way to force gnuplot to ignore the error? Or can I start gnuplot directly with a certain terminal (e.g. png)?
Thanks
Sandra
$ gnuplot
G N U P L O T
Version 5.4 patchlevel 0 last modified 2020-07-13
Copyright (C) 1986-1993, 1998, 2004, 2007-2020
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type is now 'unknown'
set term wxt
^
unknown or ambiguous terminal type; type just 'set terminal' for a list
WARNING: Error during initialization
gnuplot>```

Not tested but I suspect you need to use the gnuplot-wx
package as there are several gnuplot packages:
gnuplot-base A command-line driven interactive function plotting utility
gnuplot-doc A command-line driven interactive function plotting utility
gnuplot-qt5 A command-line driven interactive function plotting utility
gnuplot-wx A command-line driven interactive function plotting utility
gnuplot-X11 A command-line driven interactive function plotting utility
https://cygwin.com/packages/summary/gnuplot-wx.html

"Is there any way to force gnuplot to ignore the error?" No. When a gnuplot executable is built, someone has to choose which terminal types to include. This usually depends on what support libraries they have available to them when building it. Apparently your gnuplot executable was built without the wxt terminal. If you really need that particular output mode you will need to find a different gnuplot executable or build one yourself.
On the other hand - "can I start gnuplot directly with a certain terminal (e.g. png)?". Yes. There are at least three ways to do this.
Define an environmental variable GNUTERM. For example
export GNUTERM="png truecolor size 700,500"
(But that's a linux command. I don't whether there is an equivalent on Windows)
Edit the initialization file to contain a line such as
set term png truecolor size 700,500
From the "help" text:
When gnuplot is run, it first looks for a system-wide initialization file
gnuplotrc. The location of this file is determined when the program is built
and is reported by show loadpath. The program then looks in the user's HOME
directory for a file called .gnuplot on Unix-like systems or GNUPLOT.INI on
other systems. (OS/2 will look for it in the directory named in
the environment variable GNUPLOT; Windows will use APPDATA).
Give the "set term" command as part of the command line when you run gnuplot:
gnuplot -e "set term png truecolor size 700,500"

Related

R system() not working with MODIS Reprojection Tool

I have a command that works when typed into the Terminal on a Mac (OSX El Cap), but the same command fails when called from R using system().
I am trying to batch-process MODIS satellite files using the MODIS Reprojection Tool. My software is all up to date.
This is a simple example in which I mosaic two files. The names of the two files are in a text input file called input.list. The command just tells the mrtmosaic routine where to find the input list and where to put the output.
This command works correctly in the Terminal:
/Applications/Modis_Reprojection_Tool/bin/mrtmosaic -i ~/temp/input.list -o ~/temp/output.hdf
However, if I put exactly the same string into a variable and run it from R (using RStudio), it fails:
comstring<-"/Applications/Modis_Reprojection_Tool/bin/mrtmosaic -i ~/temp/input.list -o ~/temp/output.hdf"
system(comstring)
Warning: gctp_call : Environmental Variable Not Found:
MRT_DATA_DIR nor MRTDATADIR not defined
Error: GetInputGeoCornerMosaic : General Processing Error converting lat/long coordinates to input projection coordinates.
Fatal Error, Terminating...
The strange thing is that the system knows what the environment variables are. In the terminal, the command
echo $MRT_DATA_DIR
shows the correct directory: /Applications/Modis_Reprojection_Tool/data
I don't see why it would have trouble finding the variables from an R system() call when it has no trouble in the Terminal. I'm very stumped!
I posted this question to the R help list, and two people there helped me solve the problem. They suggested (if I understood right) that the problem was that OSX El Capitan was not successfully passing environment variables to R. In any case:
These do not work:
Setting the environment variable in my .bash_profile (for example by adding and exporting MTR_DATA_DIR="/Applications/MRT/data"); or
Setting the environment variable by adding the same line to the .Rprofile file in my home directory.
These do work:
Setting the environment variable at the R command line by typing Sys.setenv(MRT_DATA_DIR="/Applications/MRT/data"); or
Setting the environment variable in the .Renviron file (which is in my home directory) by adding MRT_DATA_DIR="/Applications/MRT/data" to it; or
Typing MRT_DATA_DIR="/Applications/MRT/data" open -a Rstudio in the Terminal. This last method is an effective workaround and a useful tool in a bag of tricks, but is slightly clumsier since one has to remember to open RStudio this way each time.

How to drop into R shell after executing commands from file in R

In Python, running the interpreter with the -i flag first executes the script, then drops back into the interpreter
python -i hello.py
Hello world
>>> print("Python ftw")
Python ftw
>>>
which allows me to type commands and reach the variables after execution.
With R, this seems to be of great difficulty. I have been searching online for some time, and am surprised to see there is not so many results with the keywords "R run file shell interpreter".
With R, you can use
$ R -f myfile.R which executes and then exits the interpreter
$ Rscript myfile.R which still does the same thing.
Even worse, it does not plot when run like this and just exits without showing any signs that something has been plotted.
So, to repeat my question:
How do I make R to drop into the R shell after running commands from a file, a.k.a. a script?
Concurrently, how can I make R really plot the plots and not close them off immediately?
I can do these with Python, MATLAB, Octave, Ruby and many others, and should be able to do with R too.
I will answer your two questions separately:
How do I drop into a shell after my script has executed?
The function "browser" called with no arguments will allow to to drop into a shell on the line that it's called. Appending this to your script should do the trick.
How do I save graphics when not run in interactive mode?
First, check that there isn't a pdf file being created in your working directory. Depending on how you're running R, I believe it may be named "Rplots.pdf". Personally, however, I prefer to explicitly save graphics to a particular file, as such:
pdf("temp.pdf")
plot(rnorm(100))
dev.off()
which will save the plot in a new file called temp.pdf (and will overwrite any existing file by that name, so watch out).
Functions analagous to "pdf" exist for other image formats if you would prefer that.

Installing program (dot) on system search path in R

I'm a social scientist having a hard time struggling through the technical instructions for integrating the graphing program dotdocumented here with the sem package documented here.
I have successfully run the command pathDiagram in the sem package, which outputs code that is presumably supposed to be read into dot. The documentation for the sem package says
"To obtain graphics output directly, the dot program must be on the system search path."
I'm sure that this is a totally mundane question, but I'd really appreciate help. I'm lost.
In R execute this command:
Sys.which("dot")
This will tell you whether a system call will be able to find your 'dot' installation. You did install 'dot', right?
The Graphviz pkg file for MacOS greater than or equal to 10.6 (and your ML is 10.8) can be obtained from AT&T labs: http://www.graphviz.org/Download.php
After installing from its .pkg file (with the same Graphviz version 2.30.1 on OSX 10.6.8) I get:
> Sys.which(c("dot"))
dot
"/usr/local/bin/dot"
This does NOT open up dot. It merely confirms that the dot program can be found on by R. Running the first example on hte ?pathDiagram page only outputs a source file to the console which could be used for dot to the console, because no file argument is given, but if you add a file argument it creates a pdf file using dot with a message to the console screen:
pathDiagram(sem.dhp, min.rank='RIQ, RSES, RParAsp, FParAsp, FSES, FIQ', file="test",
max.rank='ROccAsp, REdAsp, FEdAsp, FOccAsp', output.type="graphics", graphics.fmt="pdf")
#Running dot -Tpdf -o test.pdf test.dot
This produced a file in my working directory that could be viewed with Preview.app. If you want to use dot on its own, you will need to read its manual and follow the instructions for using it in a standalone manner.
Update as per comments:
If when you type which dot in terminal, you get a response with a path, then it is safe to say that graphviz is installed.
As per pathDiagram's manual (ie, ?pathDiagram), it is not intended to return a value.
Instead, use the file argument to specify where to save the output to.
pathDiagram(model=SomeModelInR, file="path/to/file", ...)
This seems to be more of a general mac os x question, but anyway, here we go:
In your applications > utilities folder, open up terminal.
(i'm assuming dot is called dot if not please modify accordingly)
Type which dot
- this will show you the path to dot, perhaps something like /usr/bin/dot
- in this case, the path you are looking for in the next part is /usr/bin
Type echo $PATH
- this will show you several paths separated by :
- If the path you got with which dot is listed as one of those paths, then you are all set.
- If not, please see the link below on how to modify
Also see:
How To Edit Your PATH Environment Variables On Mac

Call R plots from c++ using RInside/ Rcpp

Is it possible to call the plot functions from the c++ ?
Currently when I try to do that, the ubuntu terminal sort of freezes for sometime ( may be the duration for which the 3d plot would be created and then rotated for a full 360 degrees) and then unfreezes, without ever popping a new window.
Is this the expected behavior or is there something that I am doing wrong ? How can I get the plots ( R graphics ) to run from within c++ using rinside and rcpp ?
Thnx
-Egon
Yes, there is a working examples in the Rcpp package. Look at the file functionCallback/newApiExample.r in the examples/ directory.
You may need to experiment with sleep() to 'hold' the plot for a moment, or plot to a file and then have the file displayed. It all depends but you gave little detail.
The environment variable which deals with the interactive session is R_INTERACTIVE_DEVICE.
We need to create a file named .Renviron in our home directory, and then add the following code to that file:
R_INTERACTIVE_DEVICE = X11 for Linux based systems.
anisha#linux-y3pi:~> ls .Renviron
.Renviron
anisha#linux-y3pi:~> cat .Renviron
R_INTERACTIVE_DEVICE = X11a
References:
1. http://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html
2. http://stat.ethz.ch/R-manual/R-patched/library/base/html/options.html

Disable GUI, graphics devices in R

Is there an easy way to turn of all GUI elements in R and run it solely from the command line on OSX?
I'm trying to replicate the behavior of a remote linux terminal on my OSX machine. Thus plot() should just save a file and things like CRAN mirror selection should be text, not a Tk interface. I'm having trouble finding where to set this behavior.
I had this exact question and wanted a way to do it without changing my existing code. I usually run with graphics support but sometimes I'll run a script on the server for a larger dataset and then I just want the plots to be output somewhere automatically.
In Dirk's answer Ian Fellows gives the simple solution. On the command line in R type:
options(device=pdf)
And then any plots will be written to the current directly to an Rplots.pdf file.
If you want the files to not be plotted at all then use
options(device=NULL)
For the plots you can just direct the output to a file using the pdf() command (or png(), jpeg()...).
I don't own an OS X box, but did you try to unset the X11 environment variable DISPLAY:
DISPLAY="" R --vanilla
When I do that on Linux and query R for capabilties(), x11 comes up as FALSE as desired.
I don't run OSX but you could attempt to run R from the Terminal application, rather than the Mac OSX launcher, and see whether that runs as you need.
As Matti writes, you can send output to files using the following commands; but I don't know if that's really the substance of your question.
png("pngfile.png")
plot(foo)
title(main="bar")
dev.off()
So instead of the quartz graphical object, your output goes to the file.
Similarly, you can output what would normally appear in the terminal to a file.
sink("foo.file")

Resources