ncss-tech / aqp

Algorithms for Quantitative Pedology
http://ncss-tech.github.io/aqp/
54 stars 15 forks source link

slice() no longer works #40

Closed FelipeMonts closed 6 years ago

FelipeMonts commented 6 years ago

the slice function no longer works. I have tried with the example on the introduction to SoilProfileCollection objects https://ncss-tech.github.io/AQP/aqp/aqp-intro.html and it does not work with that example either.

It seems there is a bug, probably related with the relaxing of the slice() function two weeks ago. The function slab works ok though.

sliced <- slice(sp4, fm= 0:15 ~ sand + silt + clay + name + ex_Ca_toMg) Error in UseMethod("slice") : no applicable method for 'slice_' applied to an object of class "SoilProfileCollection" ?slice slab(sp4, fm= ~ sand + silt + clay, slab.structure=c(0,10), slab.fun=mean, na.rm=TRUE) variable all.profiles value top bottom contributing_fraction 1 sand 1 47.63 0 10 1 2 silt 1 31.15 0 10 1 3 clay 1 21.11 0 10 1

dylanbeaudette commented 6 years ago

Strange, this works for me with aqp_1.14

library(aqp)

# load sample data set, a data.frame object with horizon-level data from 10 profiles
data(sp4)
str(sp4)

depths(sp4) <- id ~ top + bottom

sliced <- slice(sp4, fm= 0:15 ~ sand + silt + clay + name + ex_Ca_to_Mg)

# check the result
class(sliced)

plot(sliced, color='clay')
dylanbeaudette commented 6 years ago

Could you please send the result from sessionInfo()? There is no slice_ method, could this be related to a namespace conflict?

Do you have a specific commit in mind when you said "relaxing of the slice()"?

Thanks

dylanbeaudette commented 6 years ago

Just as I thought, this is related to dplyr:

library(aqp)
library(dplyr)

data(sp4)
str(sp4)

depths(sp4) <- id ~ top + bottom
sliced <- slice(sp4, fm= 0:15 ~ sand + silt + clay + name + ex_Ca_to_Mg)

Error as reported:

Error in UseMethod("slice_") : 
  no applicable method for 'slice_' applied to an object of class "SoilProfileCollection"
FelipeMonts commented 6 years ago

I was referring to the last commit: "relaxing slice(), no need for strict=TRUE 17 days ago"

1 parent c57f09f commit e8d62c78327ee67ad06d5a0b85d8c01e8f2fa224 @dylanbeaudette dylanbeaudette committed 17 days ago

Sesion info result:

[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] devtools_1.13.0 tidyr_0.6.2 dplyr_0.5.0 RColorBrewer_1.1-2 MASS_7.3-47 rgeos_0.3-25
[7] rgdal_1.2-11 raster_2.5-8 sp_1.2-4 plyr_1.8.4 soilDB_1.8-7 aqp_1.10
[13] Hmisc_4.0-3 ggplot2_2.2.1 Formula_1.2-1 survival_2.41-3 lattice_0.20-35

loaded via a namespace (and not attached): [1] Rcpp_0.12.10 compiler_3.4.0 base64enc_0.1-3 tools_3.4.0 rpart_4.1-11 digest_0.6.12
[7] jsonlite_1.4 memoise_1.1.0 tibble_1.3.0 gtable_0.2.0 checkmate_1.8.2 htmlTable_1.9
[13] Matrix_1.2-2 DBI_0.6-1 curl_2.6 gridExtra_2.2.1 httr_1.3.1 withr_1.0.2
[19] stringr_1.2.0 cluster_2.0.6 knitr_1.15.1 htmlwidgets_0.8 grid_3.4.0 nnet_7.3-12
[25] reshape_0.8.7 data.table_1.10.4 R6_2.1.1 plotrix_3.6-3 XML_3.98-1.9 foreign_0.8-67
[31] latticeExtra_0.6-28 reshape2_1.4.2 magrittr_1.5 backports_1.0.5 scales_0.4.1 htmltools_0.3.6
[37] splines_3.4.0 assertthat_0.2.0 mime_0.5 colorspace_1.3-2 stringi_1.1.5 acepack_1.4.1
[43] lazyeval_0.2.0 munsell_0.4.3

dylanbeaudette commented 6 years ago

This is a namespace collision, unrelated to those commits.

Three solutions:

  1. don't use dplyr (haha)
  2. load aqp *after loading dplyr
  3. specify the namespace when calling slice: aqp::slice(...)

Try one of those and I'll close the ticket if one works for you. Options 1-3 work for me.

FelipeMonts commented 6 years ago

SoilDb loaded aqp as a dependency, therefore add to the instructions, "load aqp and soilDb*after loading dplyr" It works all the way! Thank you.

dylanbeaudette commented 6 years ago

Thanks for testing. These packages are now fairly old: namespace collisions weren't quite as common back then.

FelipeMonts commented 6 years ago

Thank you for working on solving the issue I had as fast as you did. Excellent package!