Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qpdf to installr #149

Open
lehnert-b opened this issue May 6, 2020 · 6 comments
Open

add qpdf to installr #149

lehnert-b opened this issue May 6, 2020 · 6 comments

Comments

@lehnert-b
Copy link

lehnert-b commented May 6, 2020

When writing R packages one important step is to test the package thoroughly. Upload to CRAN is advised only for error-, warning- and issue-free packages. My checks (started via the respective RStudio-Buttons) produce the following warning:

WARNING
'qpdf' is needed for checks on size reduction of PDFs

So qpdf is R related software and as it does not come with an installer and users are instead advised to unzip and change their windows PATH manually. I naturally checked, if that could be done by installr just to find out, it is not yet implemented.

qpdf lives on sourceforge at http://qpdf.sourceforge.net/

May I suggest adding qpdf to the program list downloadable via installr?

BTW: Thank you for the great package!
Cheers,
Bernhard

@talgalili
Copy link
Owner

Any chance you can write a diff with this function? I'll gladly accept it to the package.

@lehnert-b
Copy link
Author

Sorry, I do not understand what a diff is in this case or from what function I should provide a diff. Within my limited abilities I am glad to help but will need more detailed instruction.

@talgalili
Copy link
Owner

talgalili commented Jun 7, 2020 via email

@burgerga
Copy link
Collaborator

The annoying thing is that install.URL("https://sourceforge.net/projects/qpdf/files/latest/download") doesn't work, because it downloads a zip and not an exe, otherwise, it would be super easy to add :(
Did you ever add a program like this before @talgalili?

What we can do is take a look at tinytex, they install to %appdata% and "tweak" the PATH (https://github.com/yihui/tinytex/blob/master/R/install.R#L138)

@burgerga
Copy link
Collaborator

burgerga commented Jan 12, 2021

Quick and dirty code which works:

install.qpdf <- function() {
  dir <- win_app_dir('qpdf')
  temp_file <- tempfile(fileext = ".zip")
  # Need to use curl, and easy link unfortunately doesn't work
  # download.file("https://sourceforge.net/projects/qpdf/files/latest/download", destfile = temp_file)
  curl::curl_download("https://sourceforge.net/projects/qpdf/files/qpdf/10.1.0/qpdf-10.1.0-bin-mingw64.zip/download", destfile = temp_file)
  unzip(temp_file, exdir = dir)
  old_path <- Sys.getenv("PATH")
  Sys.setenv(PATH = paste(old_path, file.path(dir, "qpdf-10.1.0", "bin"), sep = ";"))
}

win_app_dir = function(..., error = TRUE) {
  d = Sys.getenv('APPDATA')
  if (d == '') {
    if (error) stop('Environment variable "APPDATA" not set.')
    return(d)
  }
  file.path(d, ...)
}

You can check with Sys.which('qpdf').

Sooo, if you use a browser you can go to ''https://sourceforge.net/projects/qpdf/files/latest/download" and you will get the latest zip, but if you try that in R it doesn't know what you want, and you get the source ".tar.gz" :( (see this for official "reason").

The code above also doesn't check the path if qpdf is already present, but that adds quite a bit of PATH management code :/

In summary: will take quite a bit of work to determine the correct URL, and will take quite a bit of work to add proper PATH management :(

EDIT: this only changes the PATH for the current session, so user should be instructed to add qpdf to PATH him/herself

@talgalili
Copy link
Owner

talgalili commented Jan 15, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants