mice icon indicating copy to clipboard operation
mice copied to clipboard

Installation fails when Rprofile prints to stdout

Open brookslogan opened this issue 8 months ago • 4 comments

Before submitting the issue

  • Check whether a bug report is the right format for your issue. For questions about using the mice package, see Discussions. For theoretical background about the mice methods, see Flexible Imputation of Missing Data.
  • Please make sure that you are using the latest version of mice (e.g. with the packageVersion() or sessionInfo() function).
  • Please verify whether the bug has already been addressed (e.g. on GitHub or Stack Overflow.

Describe the bug A clear and concise description of what the bug is.

When a home Rprofile exists, and that .Rprofile produces output to stdout, installation of mice fails. (Likely the same for site Rprofiles without home Rprofiles.)

To Reproduce Create a reproducible example, see e.g. the reprex package. A good reprex uses simulated or public data to showcase the bug. We recommend using one of the incomplete datasets included in the mice package (e.g. mice::boys) and the reprex() function from the reprex package.

Paste the code and output of your reprex here.

home_rprofile_path <- "~/.Rprofile" # assuming no R_PROFILE setting
if (file.exists(home_rprofile_path )) {
  stop ('Home .Rprofile already exists; refusing to clobber with this test.')
  # (`file(home_rprofile_path, "x")` would be preferable but isn't supported)
} else { # `stop` doesn't actually stop in `reprex`
  withr::with_file(home_rprofile_path, {
    writeLines('cat("Using settings from ~/.Rprofile\n")', home_rprofile_path)
    if ("mice" %in% installed.packages()) {
      remove.packages("mice")
    }
    install.packages("mice")
  })
}
#> Installing package into '/home/fullname/R/x86_64-redhat-linux-gnu-library/4.1'
#> (as 'lib' is unspecified)
#> Warning in install.packages("mice"): installation of package 'mice' had
#> non-zero exit status

Created on 2024-06-10 with reprex v2.0.2

Running within reprex appears to reproduce the problem but not the error message to the console; this is the relevant part from running outside reprex:

g++ -m64 -std=gnu++14 -shared -L/usr/lib64/R/lib -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -o mice.so RcppExports.o legendre.o match.o matchindex.o Using settings from ~/.Rprofile -L/usr/lib64/R/lib -lR
/usr/bin/ld: cannot find Using: No such file or directory
/usr/bin/ld: cannot find settings: No such file or directory
/usr/bin/ld: cannot find from: No such file or directory
/usr/bin/ld: cannot find ~/.Rprofile: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/make/shlib.mk:10: mice.so] Error 1
ERROR: compilation failed for package ‘mice’

Expected behavior A clear and concise description of what you expect to happen without the bug.

Installation succeeds.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

This appears to occur due to this line (or this Windows equivalent). Note that Rcpp:::LdFlags() is deprecated and produces an empty string, and hasn't been needed for long enough that it likely could be dropped now.

User workarounds include temporarily renaming the problematic Rprofile, or producing output to stderr (e.g., with message()) instead of stdout in the Rprofile.

brookslogan avatar Jun 10 '24 16:06 brookslogan