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

Fails on CRAN due to setwd() to read-only installation directory #2546

Closed
mattdowle opened this issue Jan 3, 2018 · 3 comments
Closed

Fails on CRAN due to setwd() to read-only installation directory #2546

mattdowle opened this issue Jan 3, 2018 · 3 comments
Milestone

Comments

@mattdowle
Copy link
Member

Current errors on CRAN including R-patched (so it's not R-devel) pasted below.
Thanks to Kurt's investigation, it's due to data.table calling setwd() to installation directory to reach test files loaded by fread. But the installation directory is (very reasonably) now mounted read-only on CRAN and a write of the plot in non-interactive mode is failing for the ggplot2 compatibility tests.
To reproduce: install data.table, change install directory to read-only, library(data.table), library(ggplot2), test.data.table() (I didn't yet try that, but in theory that should reproduce it).
One solution is to stop using setwd() to avoid any accidental or superfluous writes there. But then all fread tests loading test files need to be changed somehow, prefixed with the location.

image

Test 167 Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", :
  cannot open file 'Rplots.pdf'
Test 167.1 Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : 
  cannot open file 'Rplots.pdf'
Test 167.2 Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : 
  cannot open file 'Rplots.pdf'
Test 168 Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : 
  cannot open file 'Rplots.pdf'
Test 168.1 Error in (function (file = if (onefile) "Rplots.pdf" else "Rplot%03d.pdf", : 
  cannot open file 'Rplots.pdf'
   
Running test id 1696 
Error in eval(exprs[i], envir) : 
5 errors out of 5946 (lastID=1751, endian==little, sizeof(long double)==16, sizeof(pointer)==8) in inst/tests/tests.Rraw on Tue Jan 2 07:11:13 2018.
Search tests.Rraw for test numbers: 167, 167.1, 167.2, 168, 168.1.
Calls: test.data.table -> sys.source -> eval -> eval
Execution halted 
@mattdowle mattdowle added this to the v1.10.6 milestone Jan 3, 2018
@mattdowle mattdowle changed the title Failed on CRAN due to Fails on CRAN due to setwd() to read-only installation directory Jan 3, 2018
@HughParsonage
Copy link
Member

I think this would be a solution

if ("package:ggplot2" %in% search() && requireNamespace("grDevices", quietly = TRUE)) {
    # Issue #2546: printing plots implicitly writes to a pdf. Unless it's
    # made explicit, it's written to the working directory, which may not
    # be writeable.
    provide_pdf <- function() tempfile(fileext = ".pdf")
    library(grDevices)
    ggplot.pdf <- provide_pdf()
    pdf(ggplot.pdf)

    # ... <ggplot2 tests>

    invisible(dev.off())
    invisible(file.remove(ggplot.pdf))
}

I believe only one call to pdf is required (each plot is put on multiple pages), but doing it for each ggplot test may make debugging easier.

I can add it to my open pull request #2545 (as I've already modified test 167) or I can defer a separate pull request until after that PR is resolved.

@MichaelChirico
Copy link
Member

Something to keep in mind -- with enough tests adding to the temporary pdf, of course the file size can be an issue. I don't know what the space allocation is on CRAN, and it would probably take hundreds of ggplot-based tests for this to be a concern anyway...

@mattdowle
Copy link
Member Author

mattdowle commented Jan 11, 2018

@HughParsonage More robust (I'm currently thinking) to not setwd() to the installation directory at all rather than identify and change tests that might be like this ggplot2 one. That's one known so far and there might be more. Is it any plotting (base too) that is writing to a plot file in current directory, then, when run from R CMD check? I didn't know it did that. Anyway, PR attempted ...

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

No branches or pull requests

3 participants