This should be reproducible but I'm not sure it qualifies as a bug. It seems like an unanticipated interaction between FIESTA and the RpostgreSQL package. Here are some details:
In a fresh R session run the first modGBpop example from the FIESTA - Green-book Estimators vignette
POP1: FIADB POPULATION - Get population data for area and tree estimates for Wyoming, using post-stratification
library(FIESTA)
GBpopdat <- modGBpop(
popTabs = list(cond = FIESTA::WYcond, # FIA plot/condition data
tree = FIESTA::WYtree, # FIA tree data
seed = FIESTA::WYseed), # FIA seedling data
popTabIDs = list(cond = "PLT_CN"), # unique ID of plot in cond
pltassgn = FIESTA::WYpltassgn, # plot assignments
pltassgnid = "CN", # unique ID of plot in pltassgn
pjoinid = "PLT_CN", # plot id to join to pltassgn
unitarea = WYunitarea, # area by estimation units
unitvar = "ESTN_UNIT", # name of estimation unit
strata = TRUE, # if using post-stratification
stratalut = WYstratalut, # strata classes and pixels counts
strata_opts = strata_options(getwt = TRUE) # strata options
)
next run the first modGBtree example from the same vignette
POP1: 1.1 Net cubic-foot volume of live trees, Wyoming, 2011-2013
## Return raw data and titles
## Total net cubic-foot volume of live trees (at least 5 inches diameter), Wyoming, 2011-2013
tree1.1 <- modGBtree(
GBpopdat = GBpopdat, # pop - population calculations
landarea = "FOREST", # est - forest land filter
sumunits = TRUE, # est - sum estimation units to population
estvar = "VOLCFNET", # est - net cubic-foot volume
estvar.filter = "STATUSCD == 1", # est - live trees only
returntitle = TRUE # out - return title information
)
Everything works fine to here. But if you load the RpostgreSQL package and run the modGBtree example again it causes an error
library(RPostgreSQL)
## Return raw data and titles
## Total net cubic-foot volume of live trees (at least 5 inches diameter), Wyoming, 2011-2013
tree1.1 <- modGBtree(
GBpopdat = GBpopdat, # pop - population calculations
landarea = "FOREST", # est - forest land filter
sumunits = TRUE, # est - sum estimation units to population
estvar = "VOLCFNET", # est - net cubic-foot volume
estvar.filter = "STATUSCD == 1", # est - live trees only
returntitle = TRUE # out - return title information
)
> Error in if (nrow(treex) == 0) { : argument is of length zero
Checking for and detaching the RPostgreSQL package before running the modGBtree code will solve the problem. A possible modification to the FIESTA code in datSumTree.R to specify SQLite driver the drv="RSQLite" at line 688 (and possibly line 708) seems to prevent the error in this example:
sqldf::sqldf(tree.qry, dbname=dbname, drv="RSQLite")
I'm not sure if this would cause other problems, but I wanted to pass it along in case it helps anyone who might have RPostgreSQL loaded in their environment while calling FIESTA functions. Thank you!
This should be reproducible but I'm not sure it qualifies as a bug. It seems like an unanticipated interaction between FIESTA and the RpostgreSQL package. Here are some details:
In a fresh R session run the first modGBpop example from the FIESTA - Green-book Estimators vignette
POP1: FIADB POPULATION - Get population data for area and tree estimates for Wyoming, using post-stratification
next run the first modGBtree example from the same vignette
POP1: 1.1 Net cubic-foot volume of live trees, Wyoming, 2011-2013
Everything works fine to here. But if you load the RpostgreSQL package and run the modGBtree example again it causes an error
library(RPostgreSQL)Checking for and detaching the RPostgreSQL package before running the modGBtree code will solve the problem. A possible modification to the FIESTA code in datSumTree.R to specify SQLite driver the drv="RSQLite" at line 688 (and possibly line 708) seems to prevent the error in this example:
sqldf::sqldf(tree.qry, dbname=dbname, drv="RSQLite")I'm not sure if this would cause other problems, but I wanted to pass it along in case it helps anyone who might have RPostgreSQL loaded in their environment while calling FIESTA functions. Thank you!