ateucher / rmapshaper

An R wrapper for the mapshaper javascript library
http://andyteucher.ca/rmapshaper/
Other
200 stars 13 forks source link

System mapshaper not detectable in R #109

Closed JWusagi closed 3 years ago

JWusagi commented 3 years ago

Hi there

I'm trying to use the rmapshaper_0.4.4 to simplify a large spatial file in order to upload it onto a shinyApp. It contains boundaries of all 32,844 LSOAs in England (LSOA is one geographical unit consisting around 1,500 residents). Having tried with the ms_simplify and R session aborted, I think I should grab the system mapshaper by the command "sys=TRUE" as the file is quite large:

object.size(lsoa.bound_T) 657069488 bytes

I have followed all steps in https://cran.r-project.org/web/packages/rmapshaper/vignettes/rmapshaper.html to download node and used npm install -g mapshaper to install it via the Terminal. And I can confirm they should be properly installed, as I can check their versions in Terminal:

image

However when I'm checking the existence of mapshaper in R by check_sys_mapshaper(), I still get the same ERROR message as I did before installing node and mapshaper:

image

I'm wondering how does R pick up the mapshaper installed in node from R's PATH? I know it might goes beyond what does the rmapshaper do, and relates to some knowledge about managing packages and paths on computer. But I'm wondering if anyone is able to provide some tips, or anyone has experienced something similar?

Many thanks, Jie

ateucher commented 3 years ago

Hi @JWusagi,

Can you please run the following in your Terminal:

which mapshaper
echo $PATH

And this in your R session:

Sys.which("mapshaper")
Sys.getenv("PATH")

And post the results here?

JWusagi commented 3 years ago

Hi @JWusagi,

Can you please run the following in your Terminal:

which mapshaper
echo $PATH

And this in your R session:

Sys.which("mapshaper")
Sys.getenv("PATH")

And post the results here?

Hi Andy

Thanks very much for your reply. Please see the screenshots in terminal and R session below:

Terminal: image

R: image

ateucher commented 3 years ago

Hi @JWusagi - you're correct, this isn't an rmapshaper issue per se, rather that R doesn't always pick up environment variables (such as PATH) set elsewhere (such as ~/.profile, ~./bashrc etc).

You can add to the PATH by editing your .Renviron file (usually at ~/.Renviron). The easiest way to find and edit it is with usethis::edit_r_environ(). Then add the following line to the file:

PATH=/Users/JWusagi/.npm-global/bin/:$PATH

Alternatively, I think you can change where npm packages are installed to (or at least symlinked to) with something like:

npm config set prefix /usr/local

which should symlink your global npm packages to /usr/local/bin which is on your PATH in R. You may need to reinstall mapshaper, though I'm not 100% sure.

JWusagi commented 3 years ago

Hi @JWusagi - you're correct, this isn't an rmapshaper issue per se, rather that R doesn't always pick up environment variables (such as PATH) set elsewhere (such as ~/.profile, ~./bashrc etc).

You can add to the PATH by editing your .Renviron file (usually at ~/.Renviron). The easiest way to find and edit it is with usethis::edit_r_environ(). Then add the following line to the file:

PATH=/Users/JWusagi/.npm-global/bin/:$PATH

Alternatively, I think you can change where npm packages are installed to (or at least symlinked to) with something like:

npm config set prefix /usr/local

which should symlink your global npm packages to /usr/local/bin which is on your PATH in R. You may need to reinstall mapshaper, though I'm not 100% sure.

Hi @ateucher

Thanks so much - it works perfectly! I tried out your first suggestion and the system mapshaper perfectly gets engaged for large files. I'll close this issue then if you are happy?

Thanks again, Jie

ateucher commented 3 years ago

Great, thanks for reporting back!