ncss-tech / SoilTaxonomy

A System of Soil Classification for Making and Interpreting Soil Surveys
https://ncss-tech.github.io/SoilTaxonomy/
GNU General Public License v3.0
14 stars 2 forks source link

List entire taxonomic breakdown instead of queried level of hierarchy #42

Closed MollicMeyer closed 1 year ago

MollicMeyer commented 1 year ago

I'm not sure if this package is already capable of this option, but it's nice to to query a subgroup (or higher) and get all the levels at once.

Alltax <- function(x)
  {
  require(SoilTaxonomy)
  levels <- c("order", "suborder", "greatgroup", "subgroup")
  for(i in levels){
    n <- getTaxonAtLevel(x, level = i)
    print(paste0(i, " = ", n))}
}

Alltax('hapludolls')

[1] "order = mollisols"
[1] "suborder = udolls"
[1] "greatgroup = hapludolls"
[1] "subgroup = NA"
dylanbeaudette commented 1 year ago

Hi Meyer,

Does this work?

getChildTaxa('Ultisols')
MollicMeyer commented 1 year ago

Hi Dylan,

Thanks for the quick response. This package works great for new students trying to enter legacy data but don't know what they're looking at.

It looks like that function lists all the possible lower taxa options from the book. My thought was if you wanted all levels from a single input, the function could return them, instead of having to specify which level you wanted aka. getTaxonAtLevel("hapludolls", level = "order')

brownag commented 1 year ago

Thanks @MollicMeyer, this is a great suggestion. I think I had intended getTaxonAtLevel() to work at all levels at one point, but currently requires the level be specified. I will implement this change and leave this issue open for your feedback

MollicMeyer commented 1 year ago

Thank you @brownag !

brownag commented 1 year ago

Try the latest (712db07) from GitHub. I now get:

library(SoilTaxonomy)

# as before (order is default)
getTaxonAtLevel("hapludolls")
#>  hapludolls 
#> "mollisols"

# as before
getTaxonAtLevel("hapludolls", level = "order")
#>  hapludolls 
#> "mollisols"

# new simplify argument (forces data.frame result)
getTaxonAtLevel("hapludolls", level = "order", simplify = FALSE)
#>                order
#> hapludolls mollisols

# always data.frame result when level has length > 1
getTaxonAtLevel("hapludolls", level = c("order", "suborder", "greatgroup", "subgroup"))
#>                order suborder greatgroup subgroup
#> hapludolls mollisols   udolls hapludolls     <NA>

# works the same with multiple taxa (row names are inputs, colnames are levels)
getTaxonAtLevel(c("haploxerolls", "hapludolls"), level = c("order", "suborder", "greatgroup", "subgroup"))
#>                  order suborder   greatgroup subgroup
#> haploxerolls mollisols  xerolls haploxerolls     <NA>
#> hapludolls   mollisols   udolls   hapludolls     <NA>
dylanbeaudette commented 1 year ago

Thanks @brownag this is a nice addition.

MollicMeyer commented 1 year ago

@brownag I just installed from the git version. Seems to be a data.frame merge error:

getTaxonAtLevel(c("haploxerolls", "hapludolls"), level = c("order", "suborder", "greatgroup", "subgroup"))

Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column
brownag commented 1 year ago

@MollicMeyer Hmm... make sure you've successfully installed the new version from GH. Can you try to restart your session and make sure no remnants from past sessions get reloaded? I am unable to reproduce that error--the same command is now used in the unit tests. It seems to pass on my computer and on the different test platforms as follows...

library(SoilTaxonomy)

getTaxonAtLevel(c("haploxerolls", "hapludolls"), level = c("order", "suborder", "greatgroup", "subgroup"))
#>                  order suborder   greatgroup subgroup
#> haploxerolls mollisols  xerolls haploxerolls     <NA>
#> hapludolls   mollisols   udolls   hapludolls     <NA>
MollicMeyer commented 1 year ago

@brownag Thanks for double checking. Not sure what's wrong with this machine, but the function performs properly on another device.