zoonproject / zoon

The zoon R package
Other
61 stars 13 forks source link

ExtractAndCombData() bugs when occurrence data is a tibble #417

Open Rekyt opened 6 years ago

Rekyt commented 6 years ago

Hey there, Thank you for building zoon! It seems to be such a flexible tool for SDMs. I'm currently playing with it to build stacked SDMs an encountered a simple bug.

When using an occurrence object of class "tbl_df" "tbl" "data.frame", the ExtractAndCombData() function fails and make the workflow fail, while if it's only a data.frame it works perfectly.

My current workaround is to use as.data.frame() before using the object inside LocalOccurrenceDataFrame().

Here is a minimal reprex:

Reproductible Example ```r library("zoon") #> Le chargement a nécessité le package : raster #> Le chargement a nécessité le package : sp library("tidyverse") #> -- Attaching packages --------------------------------------------------------------------------------------------- tidyverse 1.2.1 -- #> v ggplot2 2.2.1.9000 v purrr 0.2.4 #> v tibble 1.4.2 v dplyr 0.7.4 #> v tidyr 0.8.0 v stringr 1.3.0 #> v readr 1.1.1 v forcats 0.3.0 #> -- Conflicts ------------------------------------------------------------------------------------------------ tidyverse_conflicts() -- #> x ggplot2::calc() masks raster::calc() #> x tidyr::extract() masks raster::extract() #> x dplyr::filter() masks stats::filter() #> x dplyr::lag() masks stats::lag() #> x dplyr::select() masks raster::select() env_raster = raster(matrix(1:10)) occ = data_frame(cell = 1:10, presence = c(rep(1, 5), rep(0, 5))) %>% mutate(xy = cell %>% map(~xyFromCell(env_raster, .x) %>% as.data.frame())) %>% unnest(xy) LoadModule("LocalOccurrenceDataFrame") #> [1] "LocalOccurrenceDataFrame" LoadModule("LocalRaster") #> [1] "LocalRaster" LoadModule("NoProcess") #> [1] "NoProcess" # ExtractAndCombData does bug when occurrence data is a tibble zoon_bugs = workflow( occurrence = LocalOccurrenceDataFrame( occ, occurrenceType = "presence/absence", columns = c(long = "x", lat = "y", value = "presence")), covariate = LocalRaster(env_raster), process = NoProcess, model = LogisticRegression, output = NoOutput) #> #> Attachement du package : 'assertthat' #> The following object is masked from 'package:tibble': #> #> has_name #> Covariate raster does not have a projection, zoon will assume this is in the same projection as your occurrence data #> Caught errors: #> Error in .doCellFromXY(object@ncols, object@nrows, object@extent@xmin, : Not compatible with requested type: [type=list; target=double]. #> #> Error: Stopping workflow due to error in ExtractAndCombData, a function that combines occurrence and covariate data. #> The process failed. The partially completed workflow has been saved as a temporary file. Load the partially completed workflownamed "output" by using load("C:/Users/grenie/AppData/Local/Temp/RtmpSkxTUK/file2a2c44d48ec.rdata") # ExtractAndCombData does not bug when occurrence data is only a data.frame zoon_no_bug = workflow( occurrence = LocalOccurrenceDataFrame( occ %>% as.data.frame(), occurrenceType = "presence/absence", columns = c(long = "x", lat = "y", value = "presence")), covariate = LocalRaster(env_raster), process = NoProcess, model = LogisticRegression, output = NoOutput) #> Covariate raster does not have a projection, zoon will assume this is in the same projection as your occurrence data #> Warning: glm.fit: algorithm did not converge #> Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred ```
Session Info ```r devtools::session_info() #> Session info ------------------------------------------------------------- #> setting value #> version R version 3.4.4 (2018-03-15) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate French_France.1252 #> tz Europe/Paris #> date 2018-03-26 #> Packages ----------------------------------------------------------------- #> package * version date source #> assertthat * 0.2.0 2017-04-11 CRAN (R 3.4.0) #> backports 1.1.2 2017-12-13 CRAN (R 3.4.2) #> base * 3.4.4 2018-03-15 local #> bindr 0.1.1 2018-03-13 CRAN (R 3.4.4) #> bindrcpp * 0.2 2017-06-17 CRAN (R 3.4.0) #> bitops 1.0-6 2013-08-17 CRAN (R 3.4.0) #> broom 0.4.3 2017-11-20 CRAN (R 3.4.2) #> cellranger 1.1.0 2016-07-27 CRAN (R 3.4.0) #> cli 1.0.0 2017-11-08 Github (r-lib/cli@ab1c3aa) #> colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0) #> commonmark 1.4 2017-09-01 CRAN (R 3.4.1) #> compiler 3.4.4 2018-03-15 local #> crayon 1.3.4 2017-09-16 CRAN (R 3.4.1) #> datasets * 3.4.4 2018-03-15 local #> devtools 1.13.5 2018-02-18 CRAN (R 3.4.3) #> digest 0.6.15 2018-01-28 CRAN (R 3.4.3) #> dismo 1.1-4 2017-01-09 CRAN (R 3.4.0) #> dotCall64 0.9-5.2 2018-01-11 CRAN (R 3.4.3) #> dplyr * 0.7.4 2017-09-28 CRAN (R 3.4.2) #> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.0) #> fields 9.6 2018-01-29 CRAN (R 3.4.3) #> forcats * 0.3.0 2018-02-19 CRAN (R 3.4.3) #> foreign 0.8-69 2017-06-22 CRAN (R 3.4.4) #> formatR 1.5 2017-04-25 CRAN (R 3.4.0) #> ggplot2 * 2.2.1.9000 2018-01-10 Github (tidyverse/ggplot2@4ee6c94) #> glue 1.2.0 2017-10-29 CRAN (R 3.4.2) #> graphics * 3.4.4 2018-03-15 local #> grDevices * 3.4.4 2018-03-15 local #> grid 3.4.4 2018-03-15 local #> gtable 0.2.0 2016-02-26 CRAN (R 3.4.0) #> haven 1.1.1 2018-01-18 CRAN (R 3.4.3) #> hms 0.4.2 2018-03-10 CRAN (R 3.4.3) #> htmltools 0.3.6 2017-04-28 CRAN (R 3.4.0) #> httpuv 1.3.6.2 2018-03-02 CRAN (R 3.4.3) #> httr 1.3.1 2017-08-20 CRAN (R 3.4.1) #> jsonlite 1.5 2017-06-01 CRAN (R 3.4.0) #> knitr 1.20 2018-02-20 CRAN (R 3.4.3) #> lattice 0.20-35 2017-03-25 CRAN (R 3.4.4) #> lazyeval 0.2.1 2017-10-29 CRAN (R 3.4.2) #> lubridate 1.7.3 2018-02-27 CRAN (R 3.4.3) #> magrittr 1.5 2014-11-22 CRAN (R 3.4.0) #> maps 3.2.0 2017-06-08 CRAN (R 3.4.3) #> maptools 0.9-2 2017-03-25 CRAN (R 3.4.0) #> memoise 1.1.0 2017-04-21 CRAN (R 3.4.0) #> methods * 3.4.4 2018-03-15 local #> mnormt 1.5-5 2016-10-15 CRAN (R 3.4.0) #> modelr 0.1.1 2017-07-24 CRAN (R 3.4.1) #> munsell 0.4.3 2016-02-13 CRAN (R 3.4.0) #> nlme 3.1-131.1 2018-02-16 CRAN (R 3.4.4) #> parallel 3.4.4 2018-03-15 local #> pillar 1.2.1 2018-02-27 CRAN (R 3.4.3) #> pkgconfig 2.0.1 2017-03-21 CRAN (R 3.4.0) #> plyr 1.8.4 2016-06-08 CRAN (R 3.4.0) #> psych 1.7.8 2017-09-09 CRAN (R 3.4.1) #> purrr * 0.2.4 2017-10-18 CRAN (R 3.4.2) #> R.methodsS3 1.7.1 2016-02-16 CRAN (R 3.4.0) #> R.oo 1.21.0 2016-11-01 CRAN (R 3.4.0) #> R.utils 2.6.0 2017-11-05 CRAN (R 3.4.2) #> R6 2.2.2 2017-06-17 CRAN (R 3.4.0) #> randomForest 4.6-14 2018-03-25 CRAN (R 3.4.4) #> raster * 2.6-7 2017-11-13 CRAN (R 3.4.2) #> Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.4) #> RCurl 1.95-4.10 2018-01-04 CRAN (R 3.4.3) #> readr * 1.1.1 2017-05-16 CRAN (R 3.4.0) #> readxl 1.0.0 2017-04-18 CRAN (R 3.4.0) #> reshape2 1.4.3 2017-12-11 CRAN (R 3.4.3) #> rfigshare 0.3.7.100 2018-03-22 Github (ropensci/rfigshare@a08dcda) #> rgdal 1.2-18 2018-03-17 CRAN (R 3.4.4) #> RJSONIO 1.3-0 2014-07-28 CRAN (R 3.4.0) #> rlang 0.2.0 2018-02-20 CRAN (R 3.4.3) #> rmarkdown 1.9 2018-03-01 CRAN (R 3.4.3) #> roxygen2 6.0.1 2017-02-06 CRAN (R 3.4.0) #> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3) #> rstudioapi 0.7 2017-09-07 CRAN (R 3.4.1) #> rvest 0.3.2 2016-06-17 CRAN (R 3.4.0) #> rworldmap 1.3-6 2016-02-03 CRAN (R 3.4.0) #> scales 0.5.0.9000 2018-01-10 Github (hadley/scales@d767915) #> SDMTools 1.1-221 2014-08-05 CRAN (R 3.4.0) #> sp * 1.2-7 2018-01-19 CRAN (R 3.4.3) #> spam 2.1-2 2017-12-22 CRAN (R 3.4.3) #> stats * 3.4.4 2018-03-15 local #> stringi 1.1.7 2018-03-12 CRAN (R 3.4.3) #> stringr * 1.3.0 2018-02-19 CRAN (R 3.4.3) #> testthat 2.0.0 2017-12-13 CRAN (R 3.4.2) #> tibble * 1.4.2 2018-01-22 CRAN (R 3.4.3) #> tidyr * 0.8.0 2018-01-29 CRAN (R 3.4.3) #> tidyselect 0.2.4 2018-02-26 CRAN (R 3.4.3) #> tidyverse * 1.2.1 2017-11-14 CRAN (R 3.4.3) #> tools 3.4.4 2018-03-15 local #> utils * 3.4.4 2018-03-15 local #> withr 2.1.2 2018-03-15 CRAN (R 3.4.3) #> XML 3.98-1.10 2018-02-19 CRAN (R 3.4.3) #> xml2 1.2.0 2018-01-24 CRAN (R 3.4.3) #> yaml 2.1.18 2018-03-08 CRAN (R 3.4.3) #> zoon * 0.6.3 2018-03-22 Github (zoonproject/zoon@5114072) ```
timcdlucas commented 6 years ago

Thanks for reporting this! As tidyverse is so common now, this will definitely be a recurring problem. We'll check this out.

Actually it might be easiest for us to just put an if(class(data) == 'tibble') data <- as.data.frame(tibble) type check in. Or maybe it's indicative of some other underlying issues.