Skip to content

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

Description

@mattdowle

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 

Activity

  1. added this to the milestone on Jan 3, 2018
  2. changed the title [-]Failed on CRAN due to [/-] [+]Fails on CRAN due to setwd() to read-only installation directory[/+] on Jan 3, 2018
  3. HughParsonage commented on Jan 8, 2018

    @HughParsonage
    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.

  4. MichaelChirico commented on Jan 8, 2018

    @MichaelChirico
    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...

  5. mattdowle commented on Jan 11, 2018

    @mattdowle
    MemberAuthor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions