OCHA-DAP / hdx-signals

HDX Signals
https://un-ocha-centre-for-humanitarian.gitbook.io/hdx-signals/
GNU General Public License v3.0
6 stars 0 forks source link

Fortran/Matrix/renv issue on `improve-comms` branch #21

Closed zackarno closed 1 year ago

zackarno commented 1 year ago

I pulled the latest from the improve-comms branch and ran renv::restore() and get the following error

clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Matrix.so] Error 1
ERROR: compilation failed for package ‘Matrix’
* removing ‘/Users/zackarno/Documents/CHD/repos/pa-global-monitoring/renv/staging/1/Matrix’
------------------------------------------------------------------------------ 
R was unable to find one or more FORTRAN libraries during compilation.
This often implies that the FORTRAN compiler has not been properly configured.
Please see https://stackoverflow.com/q/35999874 for more information.

Reason(s):
- 'ld: library not found for -lgfortran'
install of package 'Matrix' failed [error code 1]

I do have Matrix package working in my non-renv projects. The link provided in the error message includes lot's of discussion not specifically related to {renv} and no singular solution.

It seems like the best solution (if possible) would be to include the necessary fortran deps to the renv set up? Otherwise we would have to rely on setting up dependencies outside of renv?

another SO thread on topic

caldwellst commented 1 year ago

We can't install system level requirements in renv, it just isn't possible. You have to manually install them and ensure they are properly linked to R. There are quite a few system level requirements not available by default on remote machines, which is why we have this line in the GitHub Actions yaml.

sudo apt-get install -y -f libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev libudunits2-dev libgdal-dev

However, ubuntu-latest (and nearly all Ubuntu images since 2020) come with GNU Fortran pre-installed and we don't have to do any further setup. Hence, we don't have any errors in our monitoring workflows on GitHub Actions. Also, this branch didn't edit the renv lock file, so no renv errors should arise.

In that SO topic you linked, it tells you how to install it. I'm not sure why you are having issues, but could be because the Matrix installation in the environment is different from your other R installations, and maybe you installed gfortran using homebrew? Sadly, this is machine specific, so I'm going to close the repository issue and you'll have to figure out why it is happening on your machine at this time, although I'm happy to help.

What I have done is add a new action to this branch, test-renv, which just runs the build setup and restoration, which we can use to ensure that R package installation and restoration in renv is working properly in case we do edit the environment or lock file.

zackarno commented 1 year ago

Thanks for the explanation! I'll post the trouble-shooting and hopefully eventually a work-around in this issue for documentation and we can decide if we want to include the steps somewhere else.

I'm not sure how or why but my lockfile is out of sync.

When I run ipc_get_population()$country I encounter alot of warnings which seem a bit suspicious. This is what made me wonder if perhaps Ripc package had been updated and when I started trying to update my packages and encountering issues.

Anyways we were talking about potentially testing out {capsule} so I will post that here - in this issue/thread might be useful for us to point ourselves or others to one day.

https://milesmcbain.micro.blog/2022/06/04/i-really-should.html

zackarno commented 1 year ago

from warning message link: "What is happening is your code is not being run under gcc instead it is being forwarded to clang"

seems to be the case- when I run gcc --version in the terminal I get

Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

in an R session running system("gcc --version") in both {renv} and non-renv project produces the same output as above. Not really sure how {Matrix} is then installed fine on my system, but can't be in {renv}

zackarno commented 1 year ago
image

Lol ^

So I updated to R 4.3.1 for mac (not with homebrew)and the issue was fixed.

You will see that in the download link above they explicitly mention the fortran issue with macs and say that users "may need to download the corresponding GNU Fortran compiler from https://mac.r-project.org/tools/" - so far, have not needed to do this last part

But the issue that got me here in the first place (the warnings with ipc_get_population()$country) still persist - so I can open an issue for that if you think it is important

caldwellst commented 1 year ago

No, not important, don't worry about those, I will put a PR in. They added in chronic analyses to the IPC API about a month ago, and they don't have dates. I'll suppress the warnings explicitly, just hadn't gotten around to it yet as we filter those around anyway as we aren't interested in them for alerts.