hunter-stanke / rFIA

rFIA
https://rfia.netlify.com/
47 stars 23 forks source link

fa_mean doesn't exist #43

Open jamie-dhoover opened 1 year ago

jamie-dhoover commented 1 year ago

The area mean calculation seems to have changed or is throwing an error - any suggestions on how to fix it?

Error in dplyr::select(): ! Can't subset columns that don't exist. ✖ Column fa_mean doesn't exist.

Reproducible code:

data(fiaRI)
fiaRI_mr <-clipFIA(fiaRI, mostRecent = T)
#does not work
tpaRI<- tpa(fiaRI_mr)
#works
#tpa(fiaRI_mr, byPlot=T)

If I change the tpa to include byPlot [ tpa(fiaRI_mr, byPlot=T) ] there is not an error. I need both calculations. Thanks!

seyounger commented 1 year ago

I am also experiencing this.

maine-gis-forester commented 1 year ago

same experience here with both CRAN and dev versions.

brunoks1 commented 1 year ago

I got the same error for biomass and area functions.

brunoks1 commented 1 year ago

I found the problem,

somehow, somewhere, fa_mean and fa_var is written as fa_mean_mean and fa_var_var

I worked on the biomass function using trace("biomass",edit=TRUE).

Here was my workaround:

aEst <- aEst %>% dplyr::group_by(!!!aGrpSyms) %>% dplyr::summarize(dplyr::across(dplyr::everything(), sum, na.rm = TRUE)) %>% dplyr::ungroup() %>% dplyr::select(!!!aGrpSyms, fa_mean_mean, fa_var_var, nPlots.y)

aEst$fa_mean <- aEst$fa_mean_mean
aEst$fa_var <- aEst$fa_var_var

tEst <- tEst %>% dplyr::group_by(!!!grpSyms) %>% dplyr::summarize(dplyr::across(dplyr::everything(), 
  sum, na.rm = TRUE)) %>% dplyr::ungroup() %>% dplyr::left_join(aEst, 
  by = aGrpBy)

tEst$bPlot_mean <- tEst$bPlot_mean_mean
tEst$cPlot_mean <- tEst$cPlot_mean_mean
tEst$bPlot_var <- tEst$bPlot_var_var
tEst$cPlot_var <- tEst$cPlot_var_var
tEst$bPlot_cv <- tEst$bPlot_cv_cv
tEst$cPlot_cv <- tEst$cPlot_cv_cv

tEst <- tEst %>% dplyr::mutate(BIO_TOTAL = bPlot_mean, 
  CARB_TOTAL = cPlot_mean, AREA_TOTAL = fa_mean, BIO_ACRE = BIO_TOTAL/AREA_TOTAL, 
  CARB_ACRE = CARB_TOTAL/AREA_TOTAL, BIO_TOTAL_VAR = bPlot_var, 
  CARB_TOTAL_VAR = cPlot_var, AREA_TOTAL_VAR = fa_var, 
  BIO_ACRE_VAR = ratioVar(bPlot_mean, fa_mean, bPlot_var, 
    fa_var, bPlot_cv), CARB_ACRE_VAR = ratioVar(cPlot_mean, 
    fa_mean, cPlot_var, fa_var, cPlot_cv), BIO_TOTAL_SE = sqrt(bPlot_var)/BIO_TOTAL * 
    100, CARB_TOTAL_SE = sqrt(cPlot_var)/CARB_TOTAL * 
    100, AREA_TOTAL_SE = sqrt(fa_var)/AREA_TOTAL * 
    100, BIO_ACRE_SE = sqrt(BIO_ACRE_VAR)/BIO_ACRE * 
    100, CARB_ACRE_SE = sqrt(CARB_ACRE_VAR)/CARB_ACRE * 
    100, nPlots_TREE = nPlots.x, nPlots_AREA = nPlots.y, 
  N = P2PNTCNT_EU) %>% dplyr::select(!!!grpSyms, BIO_ACRE, 
  CARB_ACRE, BIO_TOTAL, CARB_TOTAL, AREA_TOTAL, BIO_ACRE_VAR, 
  CARB_ACRE_VAR, BIO_TOTAL_VAR, CARB_TOTAL_VAR, AREA_TOTAL_VAR, 
  BIO_ACRE_SE, CARB_ACRE_SE, BIO_TOTAL_SE, CARB_TOTAL_SE, 
  AREA_TOTAL_SE, nPlots_TREE, nPlots_AREA, N)
seyounger commented 1 year ago

This appears to be resolved with version 1.0.1.