Skip to content
Open
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
^\.travis\.yml$
^doc$
^Meta$
^.github/
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3

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

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ inst/doc
**/.DS_Store
doc
Meta

# pkgdown rendering
docs/
inst/docs/
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tidyREDCap
Title: Helper Functions for Working with 'REDCap' Data
Version: 1.1.2
Version: 1.1.3
Authors@R:
c(person(
given = "Raymond",
Expand Down Expand Up @@ -58,8 +58,8 @@ Description:
developed at Vanderbilt University.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (>= 3.5.0)
RoxygenNote: 7.3.3
Depends: R (>= 4.1.0)
Imports:
cli,
dplyr,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# tidyREDCap 1.1.3 (CRAN release)

* Package now depends on R >= 4.1.0 for use of pipe operator.
* Fixed vignette URLs that were causing site redirection issues with automated CRAN checks.
* Added alt text to vignette images.

# tidyREDCap 1.1.2 (CRAN release)

* Fix issues reported by CRAN with Linux and old R Windows (4.3.3) saying
Expand Down
120 changes: 80 additions & 40 deletions R/make_instrument_auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@
#' @export
#'
## @examples
make_instrument_auto <- function(df, drop_which_when = FALSE,
record_id = "record_id") {
make_instrument_auto <- function(
df,
drop_which_when = FALSE,
record_id = "record_id"
) {
if (names(df)[1] != record_id) {
stop("
stop(
"
The first variable in df must be `record_id`;
use option 'record_id=' to set the name of your custom id.", call. = FALSE)
use option 'record_id=' to set the name of your custom id.",
call. = FALSE
)
}


# Strip labels from REDCap created variables to prevent reported join (and
# perhaps pivot) issues on labeled variables.
df <- drop_label(df, record_id)


is_longitudinal <- any(names(df) == "redcap_event_name")

if (is_longitudinal) {
Expand Down Expand Up @@ -69,37 +73,49 @@ make_instrument_auto <- function(df, drop_which_when = FALSE,
record_id_col <- which(colnames(df) == record_id)
redcap_event_name_col <- which(colnames(df) == "redcap_event_name")
record_repeat_inst_col <- which(colnames(df) == "redcap_repeat_instance")

if (is_longitudinal) {
# Select rows that have data with a repeat number
if (is_repeated & !all(is.na(df[!allMissing,record_repeat_inst_col]))) {
return(df[!allMissing, c(
record_id_col,
redcap_event_name_col,
record_repeat_inst_col,
first_col:last_col
)])
# Select rows that have data with a repeat number
if (is_repeated & !all(is.na(df[!allMissing, record_repeat_inst_col]))) {
return(df[
!allMissing,
c(
record_id_col,
redcap_event_name_col,
record_repeat_inst_col,
first_col:last_col
)
])
} else {
# Longitudinal not repeated instruments
return(df[!allMissing, c(
record_id_col,
redcap_event_name_col,
first_col:last_col
)])
return(df[
!allMissing,
c(
record_id_col,
redcap_event_name_col,
first_col:last_col
)
])
}
} else {
# Select rows that have data with a repeat number
if (is_repeated & !all(is.na(df[!allMissing,record_repeat_inst_col]))) {
return(df[!allMissing, c(
record_id_col,
record_repeat_inst_col,
first_col:last_col
)])
# Select rows that have data with a repeat number
if (is_repeated & !all(is.na(df[!allMissing, record_repeat_inst_col]))) {
return(df[
!allMissing,
c(
record_id_col,
record_repeat_inst_col,
first_col:last_col
)
])
} else {
return(df[!allMissing, c(
record_id_col,
first_col:last_col
)])
return(df[
!allMissing,
c(
record_id_col,
first_col:last_col
)
])
}
}
} else {
Expand Down Expand Up @@ -157,19 +173,43 @@ fix_class_bug <- function(df) {
"fix_class_bug"


#' Drop the label from a variable
#' @description There is a reported issues with joins on data (without a reprex)
#' that seem to be caused by the labels. As a possible solution this can be
#' used to drop labels.
#' Drop the label from one or more variables
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RaymondBalise please review these edits and let me know if this should be kept or moved to another release(?). It would allow for using tidyselect methods to drop from one or more variables within the same function call.

#' @description There is a reported issue with joins on data (without a reprex)
#' that seem to be caused by the labels. As a possible solution this can be
#' used to drop labels from one or more variables.
#'
#' @param df the name of the data frame
#' @param x the quoted name of the variable
#' @param ... Variable selection using tidyselect helpers (e.g., `contains()`,
#' `starts_with()`) or column names as symbols or strings
#'
#' @export
#' @examples
#' \dontrun{
#' # Remove labels from a single variable
#' df |> drop_label(employment)
#'
#' # Remove labels from multiple variables
#' df |> drop_label(employment, marital_status)
#'
#' @return df
drop_label <- function(df, x) {
attributes(df[, which(names(df) == x)]) <- NULL
#' # Remove all demograhic labels using tidyselect helpers
#' df |> drop_label(starts_with("dem_"))
#' }
#'
#' @export
#'
#' @return df with labels removed from selected variables
drop_label <- function(df, ...) {
# Capture the variables using tidyselect
vars_idx <- tidyselect::eval_select(rlang::expr(c(...)), df)

# If no variables selected, return the dataframe as is
if (length(vars_idx) == 0) return(df)

# For each selected column, remove its attributes
for (col_idx in vars_idx) {
attributes(df[[col_idx]]) <- NULL
}

# TODO: investigate if labelled class needs to be dropped

df
}
140 changes: 0 additions & 140 deletions docs/404.html

This file was deleted.

Loading