Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with rebuilding the book #809

Closed
wacekk opened this issue Jun 20, 2022 · 11 comments
Closed

Problem with rebuilding the book #809

wacekk opened this issue Jun 20, 2022 · 11 comments
Assignees
Labels

Comments

@wacekk
Copy link

wacekk commented Jun 20, 2022

I have a problem with rebuild the book on my computer. An error is displayed:

label: 06-raster-vector-11
Quitting from lines 150-154 (06-raster-vector.Rmd) 
Błąd w poleceniu '.External(list(name = "CppMethod__invoke_notvoid", address = <pointer: (nil)>, ':
  wartość NULL przekazana jako adres symbolu
Wywołania: local ... crs -> .local -> .get_CRS -> <Anonymous> -> .External

Wykonywanie wstrzymane
Error in Rscript_render(f, render_args, render_meta, add1, add2) : 
  Failed to compile 06-raster-vector.Rmd

I have R 4.2.0, RStudio 2022.02.3 Build 492 installed. All packages are up to date: rmarkdown 2.14, bookdown 0.27
Necessary packages for the book installed with remotes :: install_github ("geocompr / geocompkg")

I have tried to compile a book in the past but never succeeded. So I decided to report the problem and ask for advice on solving it. Thank you in advance for any help.

@Robinlovelace
Copy link
Collaborator

I've seen similar error messages before and can guess the answer: remove the contents of _bookdown_files.

This is what I currently have, removing these should make the build work for you:

ls _bookdown_files 
01-introduction_cache          03-attribute-operations_files  05-geometry-operations_files  08-read-write-plot_files  10-gis_files         12-spatial-cv_files  15-eco_cache
02-spatial-data_cache          04-spatial-operations_cache    07-reproj_cache               09-mapping_cache          11-algorithms_cache  13-transport_cache   16-synthesis_cache
02-spatial-data_files          04-spatial-operations_files    07-reproj_files               09-mapping_files          11-algorithms_files  13-transport_files   index_cache
03-attribute-operations_cache  05-geometry-operations_cache   08-read-write-plot_cache      10-gis_cache              12-spatial-cv_cache  14-location_cache

Hope that helps, let us know how you get on!

@wacekk
Copy link
Author

wacekk commented Jun 21, 2022

Thanks a lot for your quick reply.

During subsequent compilation attempts I had to install many more packages, incl. rcartocolor, rmapshaper, kableExtra, rnaturalearth, rnaturalearthdata, cartogram, mlr3extralearners, stplanr.

But I still have a problem:

Błąd w poleceniu 'SpatialLinesNetwork(ways_freeway)':
  nie udało się znaleźć funkcji 'SpatialLinesNetwork'
Wywołania: local ... withVisible -> eval_with_user_handlers -> eval -> eval

On some sites, SpatialLinesNetwork appears as a function of the stplanr package, but is not officially documented. Also, after clicking on the name of this function in chapter 13 (in the version of the book on the website), a 404 error will be displayed.

@Robinlovelace
Copy link
Collaborator

Probably I will change this example for the 2nd edition. So will keep this open, thanks for reporting!

@Robinlovelace
Copy link
Collaborator

This is also being picked up by Actions now and it's most likely due to recent versions of stplanr, version 1.0.0 of which was recently released. I will fix this ASAP.

@wacekk
Copy link
Author

wacekk commented Jun 29, 2022

I marked the problematic part of the code in Chapter 13 as "eval = FALSE" and there were no more problems compiling Chapter 13. Another problem I have in Chapter 15:

Quitting from lines 464-467 (15-eco.Rmd) 
Błąd w poleceniu '.__Task__initialize(self = self, private = private, super = super, ':
  Assertion on 'feature types' failed: Must be a subset of {'logical','integer','numeric','character','factor','ordered','POSIXct'}, but has additional elements {'sfc_POINT'}.
Wywołania: local ... .__Task__initialize -> assert_subset -> makeAssertion -> mstop

Can I have a hint on how to solve it?

@Robinlovelace
Copy link
Collaborator

See #816 is it a different error?

@wacekk
Copy link
Author

wacekk commented Jul 1, 2022

Yes, it is. This is bug # 816. I was able to compile a book. Thank you very much for help.

Many times I had to compile a book from scratch because a package was missing. Below is a list of packages necessary to compile the latest version and an R script that prepares a list based on the content of the book.

List of 102 packages:

  "sf"                "spData"            "terra"             "graphics"          "dplyr"             "units"            
  "ggplot2"           "tmap"              "raster"            "geodata"           "spDataLarge"       "rmapshaper"       
 "ggrepel"           "rnaturalearth"     "mapview"           "kernlab"           "mlr3"              "mlr3learners"     
 "mlr3extralearners" "mlr3spatiotempcv"  "mlr3tuning"        "qgisprocess"       "rlang"             "tmaptools"        
 "future"            "lgr"               "mlr3viz"           "progressr"         "tictoc"            "vegan"            
 "paradox"           "purrr"             "knitr"             "readr"             "osmdata"           "leaflet"          
 "htmlwidgets"       "cranlogs"          "devtools"          "rstudioapi"        "remotes"           "sp"               
 "waldo"             "pkgload"           "sfheaders"         "bench"             "stringr"           "tidyr"            
 "pct"               "osmextract"        "gdalUtils"         "kableExtra"        "gdalUtilities"     "rcartocolor"      
 "grid"              "rasterVis"         "EPSG"              "s2"                "geosphere"         "rgdal"            
 "stplanr"           "lwgeom"            "tibble"            "mypackage"         "tidygeocoder"      "httr"             
 "xml2"              "curl"              "ows4R"             "classInt"          "RColorBrewer"      "mapdeck"          
 "viridisLite"       "shiny"             "plotly"            "cartogram"         "Rsagacmd"          "rgrass7"          
 "rstac"             "gdalcubes"         "link2GI"           "whitebox"          "RPostgreSQL"       "openeo"           
 "CGAL"              "Centroid"          "nlme"              "pROC"              "forcats"           "readODS"          
 "piggyback"         "igraph"            "revgeo"            "table"             "ranger"            "tree"             
 "rvest"             "bookdown"          "nremotes"          "rmarkdown"         "geocompkg"         "regexplain"       
library(tidyverse)
library(stringi)

list_of_files <- dir("./", pattern = "\\.Rmd$")

list_of_text <- map(list_of_files, readLines)

vector_of_packages <- c()

for (i in seq_along(list_of_text)) {
  v <- stri_extract_all_regex(list_of_text[[i]], "(?<=library\\()\\w+(?=\\))|\\w+(?=::)|(?<=require\\()\\w+(?=\\))") %>% 
    unlist() %>% 
    discard(is.na)
  vector_of_packages <- c(vector_of_packages, v)
}

vector_of_packages <- unique(vector_of_packages)

setdiff(vector_of_packages, installed.packages()[,1])

If I can ask at the end, is it possible to compile the book to a pdf file? It's more convenient to read on an e-book reader, and nowhere have I found an option to change the target format of the compilation.

@wacekk
Copy link
Author

wacekk commented Jul 1, 2022

A little update. The package name may contain a period (e.g. data.table).

library(tidyverse)
library(stringi)

list_of_files <- dir("./", pattern = "\\.Rmd$")

list_of_text <- map(list_of_files, readLines)

vector_of_packages <- map(list_of_text, ~stri_extract_all_regex(. , "(?<=library\\()(\\w|\\.)+(?=\\))|(\\w|\\.)+(?=::)|(?<=require\\()(\\w|\\.)+(?=\\))")) %>% 
  unlist() %>% 
  discard(is.na) %>% 
  unique()

setdiff(vector_of_packages, installed.packages()[,1])

And let me add that "EPSG" "mypackage" "CGAL" "Centroid" "nremotes" are not packages.

@Robinlovelace
Copy link
Collaborator

Great work @wacekk, I'm interested in packages that are required but which are not installed with remotes::install_github("geocompr/geocompkg"). Any ideas which subset of packages those are? Also see #817

@wacekk
Copy link
Author

wacekk commented Jul 1, 2022

I had the same problem. Many times I had to start over from scratch because a package was missing. But I didn't bother because I was able to deal with these errors. It takes about 30 minutes to compile on my computer so I spent quite a lot of time on it...

In my script, I assumed that the package could be used like this:

library(package_name)
require(package_name)
package_name::

My proposition:

  1. Analyze the source code of the book with this script line by line (as I did). Save the package list to some variable - e.g. "packages_in_book"
  2. Rewrite the script so that the first regular expression matches all files with the package code, and the next matches all the places where there is checking for installed packages and, if necessary, installation. I have never written an R package, so I don't know how to write dependencies in it and install them. Store the result in the second variable, "packages_in_package"
  3. Use the setdiff (packages_in_book, packages_in_package) function - this will give you a list of packages that are in the book but not in a package.

I repeat the question, is there any possibility to compile the book to .pdf format?

@Robinlovelace
Copy link
Collaborator

Hi Wacek, the latest version of the book is reproducible, as shown on actions. #817 was the biggest issue but there were and still others. In any case closing for now, let us know how you get on, thanks for the input, and good luck with it, any future feedback and especially PRs that improve the book are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants