geocompx / geocompr

Geocomputation with R: an open source book
https://r.geocompx.org/
Other
1.59k stars 584 forks source link

Error in chapter five, code chunk 6 #1085

Closed manab-prakash closed 8 months ago

manab-prakash commented 8 months ago

In chapter five, code chunk 6, running following : us_states_simp2 = rmapshaper::ms_simplify(us_states2163, keep = 0.01, keep_shapes = TRUE) gives Error: SyntaxError: Unexpected token '.'

Nowosad commented 8 months ago

Hi @manab-prakash -- I am unable to reproduce your issue. Please try to run the code below and let me know if it fails.

library(spData)
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.7.3, PROJ 9.2.1; sf_use_s2() is TRUE
us_states_simp2 = rmapshaper::ms_simplify(us_states, keep = 0.01,
                                          keep_shapes = TRUE)
#> Warning in ms_de_unit(input): Coercing these 'units' columns to class numeric:
#> AREA

Created on 2024-03-09 with reprex v2.0.2

Robinlovelace commented 8 months ago

Works fine for me too so closing for now.

manab-prakash commented 8 months ago

It does not run for me. Could it be the newer GDAL version? Or is it the faulty installation? But, the code for the book worked flawlessly for everything before this section.

library(spData)> library(sf)Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE> #> Linking to GEOS 3.12.1, GDAL 3.7.3, PROJ 9.2.1; sf_use_s2() is TRUE> us_states_simp2 = rmapshaper::ms_simplify(us_states, keep = 0.01,+ keep_shapes = TRUE)Error: SyntaxError: Unexpected token '.' In addition: Warning message: In ms_de_unit(input) : Coercing these 'units' columns to class numeric: AREA

On Mon, Mar 11, 2024 at 4:06 AM Robin Lovelace @.***> wrote:

Closed #1085 https://github.com/geocompx/geocompr/issues/1085 as completed.

— Reply to this email directly, view it on GitHub https://github.com/geocompx/geocompr/issues/1085#event-12066511762, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTL6HZWZGOOWSNZGBGKPADYXTMH7AVCNFSM6AAAAABEOEWZQCVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJSGA3DMNJRGE3TMMQ . You are receiving this because you were mentioned.Message ID: @.***>

Nowosad commented 8 months ago

Have you tried to run the code as one line? This error does not sound like an R error, but an external one...

library(spData)
library(sf)
us_states_simp2 = rmapshaper::ms_simplify(us_states, keep = 0.01, keep_shapes = TRUE)
Robinlovelace commented 8 months ago

rmapshaper::ms_simplify(us_states, keep = 0.01,+

Could the + be an issue?

manab-prakash commented 8 months ago

Well, I tried the one-liner version. It may have to do with the Linux package thing. The code works in Windows; I tested it there, too. I was trying to compile the book into a PDF to read since it is not available in this part of the world. If only there was a download PDF version button on the webpage.

On Mon, Mar 11, 2024 at 6:27 PM Robin Lovelace @.***> wrote:

rmapshaper::ms_simplify(us_states, keep = 0.01,+

Could the + be an issue?

— Reply to this email directly, view it on GitHub https://github.com/geocompx/geocompr/issues/1085#issuecomment-1988352995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTL6H7QPULHN5I6OXQCFP3YXWRCXAVCNFSM6AAAAABEOEWZQCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGM2TEOJZGU . You are receiving this because you were mentioned.Message ID: @.***>

Nowosad commented 8 months ago

Another idea, @manab-prakash -- are you using the current source code of the book? We do not have an object us_states2163 anymore in the book...

manab-prakash commented 8 months ago

Yes, I tried the newer version too. The result is the same. The source of the error seems to be from C++. It is definitely not an issue from geocompr. The complete traceback is:

traceback() 10: stop(structure(list(message = "SyntaxError: Unexpected token '.'", call = NULL, cppstack = NULL), class = c("std::invalid_argument", "C++Error", "error", "condition"))) 9: context_eval(join(src), private$context, serialize, await) 8: get_str_output(context_eval(join(src), private$context, serialize, await)) 7: evaluate_js(readLines(file, encoding = "UTF-8", warn = FALSE)) 6: ctx$source(system.file("mapshaper/mapshaper-browserify.min.js", package = "rmapshaper")) 5: ms_make_ctx() 4: apply_mapshaper_commands(data = geojson, command = call, force_FC = TRUE, sys = sys, sys_mem = sys_mem, quiet = quiet) 3: ms_sf(input, call, ...) 2: ms_simplify.sf(us_states, keep = 0.01, keep_shapes = TRUE) 1: rmapshaper::ms_simplify(us_states, keep = 0.01, keep_shapes = TRUE)