Skip to content

Commit

Permalink
add better text callout for current and total summaries #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Dec 13, 2023
1 parent 3caf5db commit b8cda06
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
35 changes: 35 additions & 0 deletions R/funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,39 @@ rdataload <- function(x){

return(out)

}

# get summaries for inline text
summ_fun <- function(dat, yrrng = NULL){

if(!is.null(yrrng)){
if(length(yrrng) == 1)
yrrng <- rep(yrrng, 2)
} else {
yrrng <- range(dat$Year)
}

# data prep
rstsum <- dat %>%
filter(Year <= yrrng[2] & Year >= yrrng[1]) %>%
filter(!is.na(Activity)) %>%
summarise(
pro = n(),
acr = sum(Acres, na.rm = T),
mil = sum(Miles, na.rm = T),
par = length(unique(Partner))
) %>%
mutate(
acr = case_when(
acr < 1 & acr > 0 ~ '< 1',
T ~ format(round(acr, 0), big.mark = ',', trim = T)
),
mil = case_when(
mil < 1 & mil > 0 ~ '< 1',
T ~ format(round(mil, 2), big.mark = ',', trim = T)
)
)

return(rstsum)

}
Loading

0 comments on commit b8cda06

Please sign in to comment.