Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 55 additions & 81 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,85 +1,59 @@
# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag.
# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches:
- main
- master
- devel
pull_request:
branches:
- main
- master
- devel
push:
branches:
- main
- master
- devel
pull_request:
branches:
- main
- master
- devel

name: R-CMD-check
name: R-CMD-check.yaml

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v2
permissions: read-all

- name: Query dependencies
run: |
install.packages('remotes')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
if: runner.os != 'Windows'
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')

- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
env:
_R_CHECK_CRAN_INCOMING_REMOTE_: false
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check")
shell: Rscript {0}

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-22.04, r: 'release', rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest"}
- {os: ubuntu-22.04, r: 'devel', rspm: "https://packagemanager.posit.co/cran/__linux__/jammy/latest"}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
95 changes: 95 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Suggests:
pharmaRTF,
withr
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
RdMacros: lifecycle
Config/testthat/edition: 3
LazyData: true
26 changes: 22 additions & 4 deletions R/regex.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#' This function allows you to extract important regular expressions used inside
#' Tplyr.
#'
#' There are two important regular expressions used within Tplyr. The
#' There are three important regular expressions used within Tplyr. The
#' format_string expression is the expression to parse format strings. This is
#' what is used to make sense out of strings like 'xx (XX.x%)' or 'a+1 (A.a+2)'
#' by inferring what the user is specifying about number formatting.
#'
#' The 'format_group' regex is the opposite of this, and when given a string of
#' numbers, such as ' 5 (34%) \[9]' will return the separate segments of numbers
#' broken into their format groups, which in this example would be ' 5',
#' '(34%)', and '\[9]'.
#' '(34%)', and '\[9]'. Lastly, the 'number_group' regex has a similar application
#' to the 'format_group' regex, but targets only numbers
#'
#' @param rx A character string with either the value 'format_string' or
#' 'format_group'
Expand All @@ -25,14 +26,17 @@
#' get_tplyr_regex('format_string')
#'
#' get_tplyr_regex('format_group')
#'
#' get_tplyr_regex('number_group')
#'
get_tplyr_regex <- function(rx=c("format_string", "format_group")) {
get_tplyr_regex <- function(rx=c("format_string", "format_group", "number_group")) {
rx <- match.arg(rx)

switch(
rx,
'format_string' = get_format_string_regex(),
'format_group' = get_format_group_regex()
'format_group' = get_format_group_regex(),
'number_group' = get_numeric_group_regex()
)
}

Expand Down Expand Up @@ -110,3 +114,17 @@ get_format_group_regex <- function() {
regex(paste0(nwsd, ws, num, nws))

}

#' Return the regex for identifying numbers within an output string
#'
#' This regex targets the individual numbers within the string
#'
#' @return A regular expression
#' @noRd
get_numeric_group_regex <- function() {
#`-?` - Matches an optional negative sign
# `(?:\d*\.\d+|\d+)` - A non-capturing group with two alternatives:
# `\d*\.\d+` - Matches decimals like `.75`, `0.56`, or `123.45`
# `\d+` - Matches integers like `1`, `523`, `56`
regex("-?(?:\\d*\\.\\d+|\\d+)")
}
17 changes: 15 additions & 2 deletions R/riskdiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,21 @@ prep_two_way <- function(comp) {
msg = paste0("There are no records for the following groups within the variable ", as_name(treat_var),
": ", paste(invalid_groups, collapse=", ")))

two_way <- numeric_data
# create the merge columns
mrg <- as_label(pop_treat_var)
names(mrg) <- as_label(treat_var)
mrg_cols <- append(mrg, map_chr(cols, as_label))

two_way <- numeric_data %>%
left_join(
select(header_n, everything(), tot_fill = n),
by = mrg_cols
) %>%
mutate(
distinct_total = if_else(is.na(distinct_total), tot_fill, distinct_total)
)

rm(mrg, mrg_cols)

# Nested layers need to plug the NAs left over - needs revision in the future
if (is_built_nest && quo_is_symbol(by[[1]])) {
Expand All @@ -188,7 +202,6 @@ prep_two_way <- function(comp) {
)
}


# If distinct is set and distinct values are there, use them
if (comp_distinct && !is.null(distinct_by)) {
two_way <- two_way %>%
Expand Down
18 changes: 9 additions & 9 deletions R/str_extractors.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#'
#' @examples
#'
#' string <- c(" 0 (0.0%)", " 8 (9.3%)", "78 (90.7%)")
#' string <- c(" 0 (0.0%)", " 8 (9.3%)", "78 (90.7%)", "-1 (-.56, .75) -523%, 56 | -34")
#'
#' str_extract_fmt_group(string, 2)
#'
Expand All @@ -31,11 +31,11 @@
str_extract_fmt_group <- function(string, format_group) {

if (!inherits(string, "character")) {
stop("Paramter `string` must be a character vector", call.=FALSE)
stop("Parameter `string` must be a character vector", call.=FALSE)
}

if (!inherits(format_group, "numeric") || (inherits(format_group, "numeric") && format_group %% 1 != 0)) {
stop("Paramter `format_group` must be an integer", call.=FALSE)
if (!inherits(format_group, c("integer", "numeric")) || (inherits(format_group, "numeric") && format_group %% 1 != 0)) {
stop("Parameter `format_group` must be an integer", call.=FALSE)
}

# Pull out regex to drive the work
Expand All @@ -57,22 +57,22 @@ str_extract_fmt_group <- function(string, format_group) {
str_extract_num <- function(string, format_group) {

if (!inherits(string, "character")) {
stop("Paramter `string` must be a character vector", call.=FALSE)
stop("Parameter `string` must be a character vector", call.=FALSE)
}

if (!inherits(format_group, "numeric") || (inherits(format_group, "numeric") && format_group %% 1 != 0)) {
stop("Paramter `format_group` must be an integer", call.=FALSE)
if (!inherits(format_group, c("integer", "numeric")) || (inherits(format_group, "numeric") && format_group %% 1 != 0)) {
stop("Parameter `format_group` must be an integer", call.=FALSE)
}

# Pull out regex to drive the work
f_grp_rx <- get_format_group_regex()
f_grp_rx <- get_numeric_group_regex()

# Pull out all the match groups and then get the numeric for the conditional number
match_groups <- str_match_all(string, f_grp_rx)

# Get the number upon which the condition will be evaluated
map_dbl(
match_groups,
~ if (nrow(.) < format_group) {NA_real_} else {as.double(.[format_group, 2])}
~ if (nrow(.) < format_group) {NA_real_} else {as.double(.[format_group, 1])}
)
}
2 changes: 1 addition & 1 deletion man/Tplyr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading