I am doing a discrepancy analysis in R and have problems displaying the tree with graphviz. I did everything as described in Studer et al 2011 (in: Guillet et al: Advances in Knowledge Discovery and Management). I use the disstree command to build my tree called tree.lcp and then try to display it with graphviz:
seqtree2dot(tree.lcp, filename="hh.lcp", seqdata=seqhh)
shell("dot -Tsvg -O hh.lcp.dot")
There is no problem with the first command but the second brings this error message:
Can not find command "dot" .
Error messages:
1: command 'C:\Windows\system32\cmd.exe /c dot -Tsvg -O hh.lcp.dot' gave status 1
2: In shell("dot -Tsvg -O hh.lcp.dot") :
'dot -Tsvg -O hh.lcp.dot' process failed - error code 1
I suppose it has something to do with th path command (see GraphViz: Windows PATH not set with new installer, issue when calling from R) but I installed GraphViz to C:\Program Files (x86)\Graphviz2.36 which I understand is the default.
Any idea, where the problem lies? And how could I include the path in the shell-command if the problem is still the path command?
Thanks! Katharina
You can specify the path as follows
shell(paste('"C:/Program Files (x86)/Graphviz2.36/dot"','-Tsvg -O hh.lcp.dot'))
However, if you want to plot a tree from dissimilarities between sequences, you are probably better to use the newer simplified seqtreedisplay function that generates the plot directly from the seqtree object, i.e., the outcome of the seqtree function. Normally, seqtreedisplay should find Graphviz by itself.
For more details, look at the help page by typing help(seqtreedisplay).
The latest TraMineR version has a new function that run everything directly. The function is called seqtreedisplay.
seqtreedisplay(tree.lcp, type="d")
Try running: TraMineR.checkupdates() to know if you have the latest stable version.
Related
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"
I'm writing a bash script (to be called from the terminal -- on a Linux system) that creates a log-file prior to initiating an 'rscript' using some simple user input. I'm however running into problems in controlling what messages are included in the log file (or sent to the terminal), and can't find any solution for excluding one specific R package-load message:
Package WGCNA 1.66 loaded.
In other words I need a way to (only) silence this specific message, which is printed when the WGCNA package is successfully loaded.
I will try to keep the code non-specific to hopefully make it easier to follow.
The below block is a skeleton (excluding some irrelevant code), and will be followed by some different variants I've tried. Where, originally i tried controlling the output from the R script using sink() and suppressPackageStartupMessages(), which - I thought - should have been enough.
bash script:
#!/usr/bin/env bash
read RDS
DATE=`date +%F-%R`
LOG=~/path/log/$DATE.log
touch $LOG
export ALLOW_WGCNA_THREADS=4
Rscript ~/path/analysis.R $RDS $DATE $LOG
R script:
#!/usr/bin R
# object set-up
rds.path <- "~/path/data/"
temp.path <- "~/path/temp/"
pp.data <- readRDS(paste0(rds.path, commandArgs(T)[1]))
file.date <- paste0(commandArgs(T)[2], "_")
# set up error logging
log.file <- file(commandArgs(T)[3], open="a")
sink(log.file, append=TRUE, type="message")
sink(log.file, append=TRUE, type="output")
# main pkg call
if(suppressPackageStartupMessages(!require(thePKG))){
stop("\nPlease follow the below link to install the requested package (thePKG) with relevant dependencies\n https://link.address")
}
# thePKG method call
cat("> Running "method"\n", append=TRUE)
module <- method(thePKG_input = pp.data, ppi_network = ppi_network)
# reset sink and close file connection
sink(type="message")
sink(type="output")
close(log.file)
This doesn't output anything to the terminal (which is good), including the following in the log-file:
Package WGCNA 1.66 loaded.
> Running "method"
Error: added error to verify that it's correctly printed to the file
I want to keep my log files as clean and on point as possible (and avoid clutter in the terminal), and therefor wish to remove the package-load message. I've tried the following...
i. Omitting the sink() call from the R script, and adding
&>> $LOG
to the bash 'Rscript' call. Resulting in the same file output as above.
ii. Same as i but substituting suppressPackageStartupMessages() with suppressMessages(), which results in the same file output as above.
iii. Same as i but added
... require(thePKG, quietly=TRUE)
in the R script # main pkg call, with the same results.
These where the potential solutions I came across, and tried in different variations with no positive results.
I also wondered if the WGCNA package was loaded "outside" of the !require-loop of thePKG, since it's not affected by suppressMessages() for that call. But, introducing an intentional error (which terminated the process) prior to the if-require(thePKG)-call removed the message -- hinting at its initiation inside the loop.
I also tried calling WGCNA by itself at the start of the R script, with an added suppressMessages() to it, but that didn't work either.
The export function used in the bash script doesn't effect the outcome (to my knowledge) and removing it extends the load message to include the following (truncated to save space):
Package WGCNA 1.66 loaded.
Important note: It appears that your system supports multi-threading, but it is not enabled within WGCNA in R.
To allow multi-threading within WGCNA with all available cores, use allowWGCNAThreads() within R. Use disableWGCNAThreads() to disable threading if necessary.
(...)
I'm aware that I could send the output (only) to /dev/null, but there's other output printed to the file (e.g. > Running "method") that I still want.
Does anyone have a suggestion for how to remove this message? I'm very new to programming in R, and just started using Linux (Ubuntu LTS), so please keep that in mind when answering.
Thanks in advance.
I could gather the following execution flow from your question:
Bash_Script ----> R_Script ----> Output_to_terminal (and also a log file probably)
For the requirements stated, following commands (in bash) could help you:
grep - This command helps you search for patterns
Pipe (|) - This is an operator in Linux which helps you redirect output of one command as input to another for further processing (For eg. A | B )
tee - This command takes any input and forwards it to a file + standard output (terminal)
So, you could mix and match the above commands in your bash file to get the desired output:
You can extend
Rscript ~/path/analysis.R $RDS $DATE $LOG
with
Rscript ~/path/analysis.R "$RDS" "$DATE" "$LOG" | grep -v "Package WGCNA" | tee "output.log"
What each command does ?
a) | -> This redirects output of preceding command as input to the next. It's more of a connector
b) grep -> Normally used to search for patterns. In this example, we use it with -v option to do a invert-match instead i.e. search for everything except Package WGCNA
c) tee -> This writes output to terminal + also redirects the same to a log file name, passed as argument. You could skip this command altogether, if not needed
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.
I'm trying to use grImport insert an eps format logo into maps I'm making using R. I'm running on OsX Mavericks, R 2.15 and GhostImport 9.07.
My code looks like this:
Library(grImport)
PostScriptTrace("~/Documents/My Projects/Project A/Images/Logo Large.eps")
Gives me this error:
GPL Ghostscript 9.07: Unrecoverable error, exit code 1
Error in PostScriptTrace("~/Documents/My Projects/Project A/Images/Logo Large.eps") :
status 1 in running command 'gs -q -dBATCH -dNOPAUSE -sDEVICE=pswrite
-sOutputFile=/dev/null -sstdout=Logo Large.eps.xml captureLogo Large.eps'
Can anyone shed any light on this ? I have no clue whats going on here
Thanks
Edit: Ok I have got it working using advice from flodel below - bu it is only importing my eps file in black and white and missing some internal details. Anyone know what the problem is now?
By the look of your file name (Logo Large.eps) I assume you're a bioinformatician trying to get a "web logo" vector image into R. Most likely this vector image contains a lot of text which by chance could contain a font which is not in your fonts directory.
To get around this problem the easiest way you have to convert the text in your post script file to outlines using ghost script. Just run the following line on the command line (NOT in R):
gs -sDEVICE=ps2write -dNOCACHE -sOutputFile=nochar_Logo_Large.eps -q -dbatch -dNOPAUSE -dQUIET Logo_Large.eps -c quit
After that you can use this new file in R:
PostScriptTrace("nochar_Logo_Large.eps", "nochar_Logo_Large.xml")
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