MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #17537] tools::compactPDF fails if file path contains spaces #6711

Closed MichaelChirico closed 4 years ago

MichaelChirico commented 4 years ago

Created attachment 2408 [details] Patch for compactPDF: handle file path with spaces

compactPDF does not compact a PDF if the file contains a space in its path name. It appears that this is because the calls to system2 do not quote the file path.

--> patch suggestion attached (based on R-devel revision 76215) resolves this issue for local tests

--> Reproducible example:

# Create two example PDFs without and with space in path path <- "test_PDFs" dir.create(path, showWarnings = FALSE)

fname_with_space <- c("test_space1.pdf", "test space2.pdf")

for (f in fname_with_space) { # Need to create a large enough PDF so that compression > 10% pdf(height = 70, width = 70, file = file.path(path, f), compress = FALSE) image(volcano, col = rainbow(1e6)) lines(runif(1e4), runif(1e4)) dev.off() }

# Call tools::compressPDF res <- tools::compactPDF(path, gs_quality = "screen")

# --> PDF without space in file name succeeded print(res) # compacted ‘test_space1.pdf’ from 440Kb to 100Kb

# --> PDF with space in file name failed print(attr(res, "na.action")) # test_PDFs/test space2.pdf # 1 # attr(,"class") # [1] "omit"

# Clean up unlink(path, recursive = TRUE)

R.version # platform x86_64-apple-darwin15.6.0 # arch x86_64 # os darwin15.6.0 # system x86_64, darwin15.6.0 # status # major 3 # minor 5.2 # year 2018 # month 12 # day 20 # svn rev 75870 # language R # version.string R version 3.5.2 (2018-12-20) # nickname Eggshell Igloo


METADATA

MichaelChirico commented 4 years ago

Thanks, in R-devel 76234.


METADATA