amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
424 stars 106 forks source link

Installation fails when Rprofile prints to stdout #646

Open brookslogan opened 1 month ago

brookslogan commented 1 month ago

Before submitting the issue

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.

stefvanbuuren commented 1 month ago

Before building, have you tried removing all src/*.o and src/*.so files?

brookslogan commented 1 month ago

I didn't have a src/ directory (within my working directory at least), as I was attempting to install from CRAN or RSPM. Here's some testing of devtools-based installation:

I should note that I am on Fedora, R version 4.1.3 (2022-03-10), devtools_2.4.5, Rcpp_1.0.12.

stefvanbuuren commented 1 month ago

Thanks for trying.

I am not on Fedora and cannot reproduce. I fear I won't be able to help.

brookslogan commented 1 month ago

Thanks for checking on this. The fix for me was as simple as #647, though I haven't done extensive testing. Thought I'd at least throw it in a PR as an option.