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")
Related
I am using macOS and trying to add an image (png) file on Jupyter Notebook markdown cell, but it keeps generating an error message that they cannot find the png file. I am not sure what is wrong with my following two codes:
![alt text]("~Users/jj/pythonworkspace/what.is.numpy.png" "What is Numpy?")
Alternatively,
<img src="~Users/jj/pythonworkspace/what.is.numpy.png">
You shouldn't be using quotations around your path or links. Also i think you meant to have an additional / after your home directory or maybe not have ~ at all. The path you're providing isn't following the macOS conventions.
You can test if that path is valid by going into terminal and running
ls /path/you/are/testing
try
![What is Numpy?](/Users/jj/pythonworkspace/what.is.numpy.png)
I am a novice trying to learn R using the swirl library. I entered the below command after which the screen just lets me type endlessly.
file.choose("mytest2.r")
Could someone help me understand what exactly is expected here and how to exit out of this? mytest2.r is just a blank file.
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 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.
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