forked from RudolfCardinal/rlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenGraphSaveGraph.R
48 lines (41 loc) · 1.83 KB
/
openGraphSaveGraph.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# openGraphSaveGraph.R
# John K. Kruschke, January 29, 2013.
#==============================================================================
# Namespace-like method: http://stackoverflow.com/questions/1266279/#1319786
#==============================================================================
openGraphSaveGraph = new.env()
#==============================================================================
# Functions
#==============================================================================
openGraphSaveGraph$openGraph = function( width=7 , height=7 , mag=1.0 , ... )
{
if ( .Platform$OS.type != "windows" ) { # Mac OS, Linux
X11( width=width*mag , height=height*mag , type="cairo" , ... )
} else { # Windows OS
windows( width=width*mag , height=height*mag , ... )
}
}
openGraphSaveGraph$saveGraph = function( file="saveGraphOutput" , type="pdf" , ... )
{
if ( .Platform$OS.type != "windows" ) { # Mac OS, Linux
if ( any( type == c("png","jpeg","jpg","tiff","bmp")) ) {
sptype = type
if ( type == "jpg" ) { sptype = "jpeg" }
savePlot( file=paste(file,".",type,sep="") , type=sptype , ... )
}
if ( type == "pdf" ) {
dev.copy2pdf(file=paste(file,".",type,sep="") , ... )
}
if ( type == "eps" ) {
dev.copy2eps(file=paste(file,".",type,sep="") , ... )
}
} else { # Windows OS
file=paste(file,".",type,sep="") # force explicit extension
savePlot( file=file , type=type , ... )
}
}
#==============================================================================
# Namespace-like method: http://stackoverflow.com/questions/1266279/#1319786
#==============================================================================
if ("openGraphSaveGraph" %in% search()) detach("openGraphSaveGraph")
attach(openGraphSaveGraph) # subsequent additions not found, so attach at the end