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

Get-my-data-in execution halted #8

Open
anelda opened this issue Apr 7, 2021 · 15 comments
Open

Get-my-data-in execution halted #8

anelda opened this issue Apr 7, 2021 · 15 comments

Comments

@anelda
Copy link

anelda commented Apr 7, 2021

When running the following code and also when following instructions in the afrilearnr README file I get the error below:

learnr::run_tutorial("get-my-data-in", "afrilearnr")

processing file: get-my-data-in.Rmd
  |.....                                                                                                          |   5%
  ordinary text without R code

  |..........                                                                                                     |   9%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |...............                                                                                                |  14%
  ordinary text without R code

  |....................                                                                                           |  18%
label: packages (with options) 
List of 1
 $ echo: logi TRUE

  |.........................                                                                                      |  23%
  ordinary text without R code

  |..............................                                                                                 |  27%
label: csv-airports (with options) 
List of 2
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE

Quitting from lines 88-104 (get-my-data-in.Rmd) 
Error: '' does not exist in current working directory ('/home/talarify/R/x86_64-pc-linux-gnu-library/4.0/afrilearnr/tutorials/get-my-data-in').

There is no way to recover and try an alternative tutorial if I click on Tutorial -> run tutorial in the tutorial tab. A "Loading tutorial" message appears with a circle that turns continuously and no back/stop button.
image

I restarted my R session, but the Loading tutorial message stays and wheel keeps on turning.

It works if I right click on the Tutorial tab and click on Reload

@andysouth
Copy link
Member

My first guess is that it may be due to lines 90 & 91, and possible linux/windows differences.

filename <- system.file("extdata/afriairports.csv", package="afrilearndata")
mydf <- readr::read_csv(filename)

@anelda can you paste those two lines into your R console and see if they work ?

@anelda
Copy link
Author

anelda commented Apr 8, 2021

Hi @andysouth

Yes, the first line works, but the second line gives this error -

Error: '' does not exist in current working directory ('/home/talarify').

@andysouth
Copy link
Member

Thanks @anelda @AnneMTreasure, this one should be fixed by 083e2e0
Can you reinstall & try again ? Thanks.

@AnneMTreasure
Copy link
Contributor

AnneMTreasure commented Apr 13, 2021

Hi @andysouth,

I reinstalled, but when running the following code (on a mac):

learnr::run_tutorial("get-my-data-in", "afrilearnr")

I get this error:

processing file: get-my-data-in.Rmd
  |...                                                                   |   5%
  ordinary text without R code

  |......                                                                |   9%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |..........                                                            |  14%
  ordinary text without R code

  |.............                                                         |  18%
label: packages (with options) 
List of 1
 $ echo: logi TRUE

  |................                                                      |  23%
  ordinary text without R code

  |...................                                                   |  27%
label: csv-airports (with options) 
List of 2
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE


── Column specification ────────────────────────────────────────────────────────
cols(
  .default = col_character(),
  id = col_double(),
  latitude_deg = col_double(),
  longitude_deg = col_double(),
  elevation_ft = col_double(),
  scheduled_service = col_double(),
  score = col_double(),
  last_updated = col_datetime(format = "")
)
ℹ Use `spec()` for the full column specifications.

  |......................                                                |  32%
  ordinary text without R code

  |.........................                                             |  36%
label: csv-crs-missing (with options) 
List of 4
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE
 $ message      : logi FALSE
 $ warning      : logi FALSE


── Column specification ────────────────────────────────────────────────────────
cols(
  .default = col_character(),
  id = col_double(),
  latitude_deg = col_double(),
  longitude_deg = col_double(),
  elevation_ft = col_double(),
  scheduled_service = col_double(),
  score = col_double(),
  last_updated = col_datetime(format = "")
)
ℹ Use `spec()` for the full column specifications.

  |.............................                                         |  41%
  ordinary text without R code

  |................................                                      |  45%
label: dataframe-airports (with options) 
List of 1
 $ echo: logi TRUE

  |...................................                                   |  50%
  ordinary text without R code

  |......................................                                |  55%
label: dataframe-sf (with options) 
List of 4
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE
 $ message      : logi FALSE
 $ warning      : logi FALSE

  |.........................................                             |  59%
  ordinary text without R code

  |.............................................                         |  64%
label: shp-countries (with options) 
List of 4
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE
 $ message      : logi FALSE
 $ warning      : logi FALSE

  |................................................                      |  68%
  ordinary text without R code

  |...................................................                   |  73%
label: kml-highways (with options) 
List of 4
 $ exercise     : logi TRUE
 $ exercise.eval: logi TRUE
 $ message      : logi FALSE
 $ warning      : logi FALSE

Quitting from lines 228-236 (get-my-data-in.Rmd) 
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
  Feature creation failed.
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 1: ICreateFeature: Mismatched geometry type
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 6: DeleteLayer() not supported by this dataset.

I also get the same error as Anelda in the comment above when clicking on the tutorials using the tutorial tab (i.e. A "Loading tutorial" message appears with a circle that turns continuously and no back/stop button).

@AnneMTreasure
Copy link
Contributor

AnneMTreasure commented Apr 13, 2021

Checking some of the other tutorials, when running:

learnr::run_tutorial("afrilearnr-crash-course", "afrilearnr")

I get the following message (also mentioned in issue #9):

Error: Tutorial "afrilearnr-crash-course" was not found in the "afrilearnr" package.
Available tutorials:
* afrilearnr
  - get-my-data-in     : "How to get your own spatial data into R"
  - openstreetmap-data : "Download and plot OpenStreetMap data from R"
  - template-tutorial  : "Blank afrimapr tutorial template"
  - test-tmap-view     : "test tmap failing in view mode when run by learner"

Of the tutorials currently shown as available in afrilearnr, get-my-data-in is the only one that doesn't load. The other three (openstreetmap-data, template-tutorial, test-tmap-view) all open and load in browser windows.

@andysouth
Copy link
Member

Thanks @AnneMTreasure

So the problem which is causing it to fail on Mac & Linux, while it seems to be OK on Windows is shown by this :

Quitting from lines 228-236 (get-my-data-in.Rmd) 
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : Feature creation failed.

CPL_write_OGR is (I think) a GDAL (Geospatial Data Abstraction Library) function. GDAL can operate differently on different systems.

Lines 228-236 contain this code which just reads in a kml and plots it :

filename <- system.file("extdata","trans-african-highway.kml", package="afrilearndata", mustWork=TRUE)
afrihighway <- sf::read_sf(filename)
mapview(afrihighway)

So this shouldn't be a problem, that code is not even writing anything, but is, and is tricky to fix.

Can you try the 3 lines of code above in your R console ?

@AnneMTreasure
Copy link
Contributor

Hi @andysouth ,

Running this code:

filename <- system.file("extdata","trans-african-highway.kml", package="afrilearndata", mustWork=TRUE)
afrihighway <- sf::read_sf(filename)
mapview(afrihighway)

The first two lines run, but this one:

mapview(afrihighway)

gives this error:

Failed to create feature 0 in file2ba66c91965e
Deleting layer not supported by driver `FlatGeobuf'
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
  Feature creation failed.
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 1: ICreateFeature: Mismatched geometry type
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 6: DeleteLayer() not supported by this dataset.

@andysouth
Copy link
Member

Thanks @AnneMTreasure seems to be a problem with either reading in or plotting the highways.

Can you try :
str(afrihighway)
head(afrihighway)

@AnneMTreasure
Copy link
Contributor

Hi @andysouth, these work:

str(afrihighway)

sf[,3] [100 × 3] (S3: sf/tbl_df/tbl/data.frame)
 $ Name       : chr [1:100] "Western Sahara (Morocco) Link" "Mauritania Border- Dakar Link" "Nouakchott- Senegal Border Link" "Western Sahara Border- Nouakchott Link" ...
 $ Description: chr [1:100] "Cairo-Dakar Highway section linking Senegal across Western Sahara to Morocco. This highway is part of the great"| __truncated__ "" "" "" ...
 $ geometry   :sfc_LINESTRING of length 100; first list element:  'XYZ' num [1:18, 1:3] -16.9 -16.9 -16.5 -16.3 -16.1 ...
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA
  ..- attr(*, "names")= chr [1:2] "Name" "Description"

head(afrihighway)

Simple feature collection with 6 features and 2 fields
Geometry type: LINESTRING
Dimension:     XYZ
Bounding box:  xmin: -17.36938 ymin: 14.76957 xmax: -6.800537 ymax: 33.98436
z_range:       zmin: 0 zmax: 0
Geodetic CRS:  WGS 84
# A tibble: 6 x 3
  Name          Description                                             geometry
  <chr>         <chr>                                           <LINESTRING [°]>
1 Western Saha… "Cairo-Dakar Highway secti… Z (-16.94778 21.34438 0, -16.85303 …
2 Mauritania B… ""                          Z (-17.36938 14.76957 0, -16.9519 1…
3 Nouakchott- … ""                          Z (-15.81069 16.52036 0, -16.11694 …
4 Western Saha… ""                          Z (-15.99128 18.08646 0, -16.01807 …
5 Marrakesh- W… ""                          Z (-12.95837 27.67623 0, -12.7002 2…
6 Rabat- Marra… ""                          Z (-8.12439 31.79238 0, -8.02002 31…

@andysouth
Copy link
Member

Interesting @AnneMTreasure . So the object looks OK, but mapview doesn't like it.

Just checking that tmap works ?
tmap::tm_shape(afrihighway) + tm_lines()

Another route to try before the mapview command : library(rgdal)

@AnneMTreasure
Copy link
Contributor

Hi @andysouth ,

tmap works:

tmap::tm_shape(afrihighway) + tm_lines()

I ran:

library(rgdal)

and reran:

mapview(afrihighway)

but still get this error:

Failed to create feature 0 in file2ba67b6ffdd3
Deleting layer not supported by driver `FlatGeobuf'
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
  Feature creation failed.
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 1: ICreateFeature: Mismatched geometry type
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 6: DeleteLayer() not supported by this dataset.

Are there any other packages I should have installed?

@andysouth
Copy link
Member

Thanks @AnneMTreasure I think this is a mapview problem, maybe you/we can submit as an issue there.

One last thing to try. The kml file has a column that is mostly empty, which I filter out when creating the afrihighway object in afrilearndata. So could try this.

#remove Description column, only has contents in first row
afrihighway <- afrihighway[ , which(names(afrihighway)!='Description')]
mapview(afrihighway)

@AnneMTreasure
Copy link
Contributor

Hi @andysouth ,

afrihighway <- afrihighway[ , which(names(afrihighway)!='Description')]
mapview(afrihighway)

still gives me:

Failed to create feature 0 in file2ba6758166f4
Deleting layer not supported by driver `FlatGeobuf'
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
  Feature creation failed.
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 1: ICreateFeature: Mismatched geometry type
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 6: DeleteLayer() not supported by this dataset.

@AnneMTreasure
Copy link
Contributor

Hi @andysouth ,

Found this GitHub issue: mapview with FlatGeoBuf not rendering

I haven't read everything in that issue and the fixes that were used, but tried this one quickly:
Using:

mapviewOptions(fgb = FALSE)

before:

mapview(afrihighway)

and a map rendered. I'm not sure if this is what this map is supposed to look like:

Rplot

For the online tutorial for intro to spatial data in R:

Section H. Read spatial data from files

The issue with rendering the plot appears here as well and I get the message:

Cannot create RasterLayer object from this file; perhaps you need to install rgdal first

I'm not sure if this helps?

@andysouth
Copy link
Member

Thanks @AnneMTreasure, good google work finding the FlatGeoBuf error 👍 . I saw that but didn't get as far as you in actually trying it. This is what makes me think this is a mapview problem and not ours. Can you just install latest version of mapview and check the error persists ? If so, can you submit this reproducible example as an issue to mapview ? That way the developers can test it at their end. Better coming from you given that it doesn't seem to happen on my windows machine.

remotes::install_github('afrimapr/afrilearndata')
library(afrilearndata)
mapview(afrihighway)

Re the other problem, better to submit that here as a separate issue. There's a chance it might be fixed by a recent commit I've made (fingers crossed).

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

No branches or pull requests

3 participants