Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:51:47+00:00 2026-06-17T10:51:47+00:00

I once did a blog on combining graphis with external programs and received a

  • 0

I once did a blog on combining graphis with external programs and received a terrific comment from a reader (-click here-) on implementing this entirely within R with ghostscript as seen below. I have been using this a bit lately and am wanting to share it with others. I’d like to modify it to make the function more intuitive and detecting the ghostscript type is one mod I’d like to do but can’t. The unix vs. windows is easy via .Platform. The sticking point is the windows 32 vs. 64 that I struggle with.

How can I use R to detect which ghostscript version (gswin32c or gswin64c) is running? Merely looking at the computer’s specifications isn’t good enough because I run gswin32c on a Win 64 machine. The idea is to remove the os argument entirely or set it to NULL and have the function try to access this information.

mergePDF <- function(infiles, outfile, os = "UNIX") {
    version <- switch(os,
        UNIX = "gs",
        Win32 = "gswin32c",
        Win64 = "gswin64c")
    pre = " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="
    system(paste(paste(version, pre, outfile, sep = ""), infiles, collapse = " "))
}


pdf("file1.pdf", width = 10, height = 8)
plot(1:10, col="red", pch = 19)
dev.off()

pdf("file2.pdf", width = 16, height = 8)
plot(1:10)
dev.off()

mergePDF("file1.pdf file2.pdf", "mergefromR.pdf", "Win32")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:51:48+00:00Added an answer on June 17, 2026 at 10:51 am

    Tyler, dude. Have I been demoted from being a Stack Ove-R-flow peer to a “reader” of your blog? Or is that a promotion 😉

    This feels a little hackish to me, but should get the job done. Add this as the first few lines of the function and remove the os argument:

    testme <- c(UNIX = "gs -version", 
                Win32 = "gswin32c -version", 
                Win64 = "gswin64c -version")
    os <- names(which(sapply(testme, system) == 0))
    

    I’ve used the -version switch so that R doesn’t try to load Ghostscript unnecessarily.

    On my Ubuntu system, when I run this, os returns, as expected, UNIX, and on my Windows system where I have the 32-bit version of Ghostscript installed, it returns Win32. Try it out on your 64-bit machine running the 32-bit GS and let me know how it works.


    Update

    After reading the help pages for system() and system2(), I learned about Sys.which(), which seems to be exactly what you’re looking for. Here it is in action on my Ubuntu system:

    Sys.which(c("gs", "gswin32c", "gswin64c"))
    #            gs      gswin32c      gswin64c 
    # "/usr/bin/gs"            ""            "" 
    names(which(Sys.which(c("gs", "gswin32c", "gswin64c")) != ""))
    # [1] "gs"
    

    Thus, OS specification can be skipped entirely in the mergePDF() function:

    mergePDF <- function(infiles, outfile) {
      gsversion <- names(which(Sys.which(c("gs", "gswin32c", "gswin64c")) != ""))
      pre = " -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="
      system(paste(paste(gsversion, pre, outfile, sep = ""), infiles, collapse = " "))
    }
    

    You may want to do some error checking. If the length of gsversion is > 1 or is 0, for instance, you may want to stop the function and prompt the user to either install Ghostscript or to verify their Ghostscript version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done this before once, I'm trying to replicate what I did so far
Once again I'm receiving structs via UDP from a C++ programm, Now I ported
I once did a programming test for a job, which involved producing ASCii art
So i remember that i once did something in another project and (later removed
if location services are turned off (after the user once did allow the service)
I recently upgraded to the iPhone 3.0 sdk. Once i did this, i needed
i did an application which has imageview to capture image from camera and a
once we send email from php using mail() function, is there any way to
Almost every programmer did it once in his life: setting some flag if a
I once did a cursory search and found no good CVS bindings for Python.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.