Colleagues,
Several days ago, I queried about using the "system" command to open a
PDF file. A number of people responded, each providing useful ideas.
I integrated these ideas into a function that others can tailor to
their needs:
OPENPDF <- function(PDFFILENAME)
{
OPENPDFCOMMAND <- "open" # applies to OS X
if (!UNIX) OPENPDFCOMMAND <- "start" # applies to
Windows
if (LINUX)
{
OPENPDFCOMMAND <- getOption("pdfviewer")
# S-
Plus does not set this option
# also, R appears to not set it in SUSE
TESTTHESE <- c("xpdf",
"evince",
"acroread")
if (is.null(OPENPDFCOMMAND)) # look for
application named ...
{
for (EachTest in TESTTHESE)
{
VALUE <-
SYSTEM(paste("locate", EachTest))
if (length(VALUE) > 0)
{ OPENPDFCOMMAND <- VALUE }
}
}
}
if (!is.null(OPENPDFCOMMAND) & file.exists(PDFFILENAME))
{ SYSTEM(paste(OPENPDFCOMMAND, PDFFILENAME)) } else
invisible()
}
This version calls other functions that I have written, e.g., UNIX and
LINUX, each of which identifies the OS. The SYSTEM command is
specific for the OS (e.g., system in OS X and Linux, shell in Windows;
intern=T in all cases).
If anyone has suggestions for improvement, I would be delighted to
receive them.
Dennis
Dennis Fisher MD
P < (The "P Less Than" Company)
Phone: 1-866-PLessThan (1-866-753-7784)
Fax: 1-415-564-2220
www.PLessThan.com
[[alternative HTML version deleted]]