Rscript leading to "Segmentation fault"

Not really sure where to ask this as it seems like a system issue but I'll ask it here.

This issue started in a Make file but also happens in regular Git bash.

Suppose we have a script, say rscript_reprex1.R

#!/usr/bin/env Rscript

Sys.sleep(1)
cli::cli_inform("Script 1 terminates successfully")

If I then try the following in Git Bash,

Rscript.exe rscript_reprex.R

The console returns Segmentation fault and I am not sure why (works fine in RStudio)

This is on R 4.4.0 for information.

Open to any suggestions to better understand this. Has anyone got a good intuition for why this would be or what I should check on my system?

No definitive answer, a few suggestions that might help pinpoint the problem.

First, check which version of Rscript.exe is actually called by Git Bash, using:

which Rscript.exe

Maybe try with an other installed version, for example:

/c/Program\ Files/R/R-4.4.0/bin/x64/Rscript.exe rscript_reprex1.R

Also, simplify the script even more using only print(). Or don't even call a saved script, does this work?

Rscript.exe -e 'print("yes")'

And since we're at this point, maybe use R.exe instead of Rscript.exe:

R.exe -e 'print("yes")'

And also see if it's only in Git Bash. Open a cmd and try the same commands, do they have the same problem? Some commands may need to be adapted, e.g.:

where Rscript.exe
"C:\Program Files\R\R-4.2.2\bin\x64\Rscript.exe" -e 'print("yes")'

Thanks for the really good ideas to try Alexis.

It turns out I'm using Rscript from C:\R\R-4.4.0\bin\Rscript.exe so I'll try the one under x64 and see if it's more consistent.

I also wonder if the non-standard R install location is causing issues.

Forgot to mention, the error is also inconsistent (appears one day, no error on another day after restarting).

Will update this post if I find the cause or a solution.

I am closing this as I don't think it's an R issue and there's been plenty of good suggestions.

For my case, Make has the wrong environment variables (HOME, TMPDIR) and Rscript directly from the command line seems to work.

I was also able to recreate the error by getting the filename wrong.

Anyone having a similar issue, I'd recommend checking the filepath is correct and maybe surrounding it in quotes for good measure.

I've give up with Make and reverted to just using (several) bash scripts to call a sequence of R scripts.

1 Like

Make can be a bit finicky. If you want to try, the pure R {targets} package has a similar logic, but does everything within R.

I've also read good things about SnakeMake and just. It might be worth considering these alternatives that have the advantages of make but maybe safer for general use.