Skip to content

Commit 7c2b0e8

Browse files
authored
Merge pull request #45 from NOAA-EDAB/style/i44-air-format
Style(#44): air formatting of functions
2 parents a830626 + 301a113 commit 7c2b0e8

36 files changed

Lines changed: 3693 additions & 2173 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Workflow derived from https://github.com/posit-dev/setup-air/tree/main/examples
2+
3+
on:
4+
push:
5+
branches: [main, dev]
6+
pull_request:
7+
8+
name: format-check.yaml
9+
10+
permissions: read-all
11+
12+
jobs:
13+
format-check:
14+
name: format-check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
19+
- name: Install
20+
uses: posit-dev/setup-air@v1
21+
22+
- name: Check
23+
run: air format . --check

R/agg_custom.R

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@
66
#'
77
#' @noRd
88

9-
10-
agg_custom <- function(data, groups, fun, agg.scale){
9+
agg_custom <- function(data, groups, fun, agg.scale) {
1110
out = atlantistools::agg_data(data = data, groups = groups, fun = fun) %>%
12-
mutate(date = as.POSIXct(time*365*86400, origin = '1964-01-01 00:00:00',tz = 'UTC'))
11+
mutate(
12+
date = as.POSIXct(
13+
time * 365 * 86400,
14+
origin = '1964-01-01 00:00:00',
15+
tz = 'UTC'
16+
)
17+
)
1318

14-
if(agg.scale == 'month') {
15-
out$time.agg = as.numeric(factor(format(out$date,format = '%m')))
16-
}else if(agg.scale == 'year'){
19+
if (agg.scale == 'month') {
20+
out$time.agg = as.numeric(factor(format(out$date, format = '%m')))
21+
} else if (agg.scale == 'year') {
1722
out$time.agg = as.numeric(factor(format(out$date, format = '%Y')))
18-
}else{
19-
out$time.agg = out$time*365
23+
} else {
24+
out$time.agg = out$time * 365
2025
}
2126

22-
match.cols = c(groups[-which(groups == 'time')],'time.agg')
27+
match.cols = c(groups[-which(groups == 'time')], 'time.agg')
2328
out.agg = out %>%
2429
group_by_at(match.cols) %>%
25-
dplyr::summarise(time = floor(min(time)),
26-
atoutput = mean(atoutput,na.rm=T),.groups="drop")
27-
dplyr::select(all_of(c(groups,'atoutput')))
30+
dplyr::summarise(
31+
time = floor(min(time)),
32+
atoutput = mean(atoutput, na.rm = T),
33+
.groups = "drop"
34+
)
35+
dplyr::select(all_of(c(groups, 'atoutput')))
2836

2937
return(out.agg)
3038
}

R/calc_mef.R

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
#'
1212
#'@noRd
1313

14-
15-
1614
calc_mef <- function(observed, expected) {
17-
1815
#remove NAs. Exist only in observed data
1916
expected <- expected[!is.na(observed)]
2017
observed <- observed[!is.na(observed)]
2118

22-
oo <- sum((observed-mean(observed))^2)
19+
oo <- sum((observed - mean(observed))^2)
2320
po <- sum((expected - observed)^2)
2421

25-
mef <- (oo-po)/oo
22+
mef <- (oo - po) / oo
2623

2724
# number of data point used in calculation
2825
n <- length(expected)
2926

30-
return(list(mef=mef,n=n))
27+
return(list(mef = mef, n = n))
3128
}

R/check_species_codes.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,29 @@
1111
#'
1212
#' @noRd
1313

14-
check_species_codes <- function(modelBiomass,speciesCodes){
15-
14+
check_species_codes <- function(modelBiomass, speciesCodes) {
1615
# use default options
1716
atlantisCodes <- modelBiomass %>%
1817
dplyr::filter(!is.na(.data$code)) %>%
1918
dplyr::distinct(.data$code) %>%
2019
dplyr::pull()
2120
# use default options
22-
if (is.null(speciesCodes)) { # select all species
21+
if (is.null(speciesCodes)) {
22+
# select all species
2323
speciesCodes <- atlantisCodes
2424
} else {
2525
# remove NA's check for codes not in atlantis
2626
speciesCodes <- speciesCodes[!is.na(speciesCodes)]
2727
# check to make sure no non atlantis codes
28-
invalidCodes <- base::setdiff(speciesCodes,atlantisCodes)
28+
invalidCodes <- base::setdiff(speciesCodes, atlantisCodes)
2929

30-
if (!(length(invalidCodes)==0)){
31-
stop("Invalid Atlantis group codes: ",paste0(invalidCodes,collapse=", "))
30+
if (!(length(invalidCodes) == 0)) {
31+
stop(
32+
"Invalid Atlantis group codes: ",
33+
paste0(invalidCodes, collapse = ", ")
34+
)
3235
}
3336
}
3437

3538
return(speciesCodes)
36-
3739
}

0 commit comments

Comments
 (0)