Currenly .sum_gfw() is defined as follows in R/calc_treecover_area.R:
.sum_gfw <- function(data, what = "coverage_area") {
# calculate loss area by year
df <- data.frame(years = 2000:2022, var = 0)
names(df)[2] <- what
my_sum <- by(data[[what]], data[["lossyear"]], sum, na.rm = TRUE)
sum_years <- as.numeric(names(my_sum))
sum_years <- sum_years + 2000
index <- match(sum_years, df[["years"]])
df[[what]][index] <- as.numeric(my_sum)
df
}
The line df <- data.frame(years = 2000:2022, var = 0) implies that 2000:2022 must be updated at each get_gfw_lossyear() to include the latest available year for the resource. This is not very intuitive and possibly error prone. I wonder if it would not be convenient to extract the year range directly from the gfw_lossyear resource being used.
Currenly
.sum_gfw()
is defined as follows inR/calc_treecover_area.R
:The line
df <- data.frame(years = 2000:2022, var = 0)
implies that2000:2022
must be updated at eachget_gfw_lossyear()
to include the latest available year for the resource. This is not very intuitive and possibly error prone. I wonder if it would not be convenient to extract the year range directly from the gfw_lossyear resource being used.