updated data import
Some checks are pending
pkgdown.yaml / pkgdown (push) Waiting to run

This commit is contained in:
Andreas Gammelgaard Damsbo 2025-03-11 13:42:57 +01:00
commit 912fff7474
No known key found for this signature in database
32 changed files with 2340 additions and 273 deletions

View file

@ -1,5 +1,5 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/columnSelectInput.R
% Please edit documentation in R/custom_SelectInput.R
\name{columnSelectInput}
\alias{columnSelectInput}
\title{A selectizeInput customized for data frames with column labels}
@ -42,4 +42,3 @@ a \code{\link[shiny]{selectizeInput}} dropdown element
Copied and modified from the IDEAFilter package
Adds the option to select "none" which is handled later
}
\keyword{internal}

View file

@ -7,6 +7,7 @@
\alias{plot_hbars}
\alias{plot_violin}
\alias{plot_scatter}
\alias{sankey_ready}
\alias{plot_sankey}
\title{Title}
\usage{
@ -20,9 +21,19 @@ plot_violin(data, x, y, z = NULL)
plot_scatter(data, x, y, z = NULL)
sankey_ready(data, x, y, z = NULL, numbers = "count")
plot_sankey(data, x, y, z = NULL, color.group = "x", colors = NULL)
}
\arguments{
\item{data}{data.frame}
\item{x}{primary variable}
\item{y}{secondary variable}
\item{z}{tertiary variable}
\item{...}{ignored for now}
\item{type}{plot type (derived from possible_plots() and matches custom function)}
@ -38,6 +49,8 @@ ggplot2 object
ggplot2 object
data.frame
ggplot2 object
}
\description{
@ -51,6 +64,8 @@ Beatiful violin plot
Beautiful violin plot
Readying data for sankey plot
Beautiful sankey plot with option to split by a tertiary group
}
\examples{
@ -63,6 +78,9 @@ mtcars |> plot_hbars(x = "carb", y = "cyl")
mtcars |> plot_hbars(x = "carb", y = NULL)
mtcars |> plot_violin(x = "mpg", y = "cyl", z = "gear")
mtcars |> plot_scatter(x = "mpg", y = "wt")
ds <- data.frame(g = sample(LETTERS[1:2], 100, TRUE), first = REDCapCAST::as_factor(sample(letters[1:4], 100, TRUE)), last = sample(c(letters[1:4], NA), 100, TRUE, prob = c(rep(.23, 4), .08)))
ds |> sankey_ready("first", "last")
ds |> sankey_ready("first", "last", numbers = "percentage")
ds <- data.frame(g = sample(LETTERS[1:2], 100, TRUE), first = REDCapCAST::as_factor(sample(letters[1:4], 100, TRUE)), last = REDCapCAST::as_factor(sample(letters[1:4], 100, TRUE)))
ds |> plot_sankey("first", "last")
ds |> plot_sankey("first", "last", color.group = "y")

20
man/drop_empty_event.Rd Normal file
View file

@ -0,0 +1,20 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/redcap_read_shiny_module.R
\name{drop_empty_event}
\alias{drop_empty_event}
\title{Drop empty events from REDCap export}
\usage{
drop_empty_event(data, event = "redcap_event_name")
}
\arguments{
\item{data}{data}
\item{event}{"redcap_event_name", "redcap_repeat_instrument" or
"redcap_repeat_instance"}
}
\value{
data.frame
}
\description{
Drop empty events from REDCap export
}

View file

@ -8,6 +8,8 @@ get_label(data, var = NULL)
}
\arguments{
\item{data}{vector or data frame}
\item{var}{variable name. Optional.}
}
\value{
character string

24
man/grepl_fix.Rd Normal file
View file

@ -0,0 +1,24 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wide2long.R
\name{grepl_fix}
\alias{grepl_fix}
\title{Matches pattern to vector based on match type}
\usage{
grepl_fix(data, pattern, type = c("prefix", "infix", "suffix"))
}
\arguments{
\item{data}{vector}
\item{pattern}{pattern(s) to match. Character vector of length 1 or more.}
\item{type}{type of match. can be one of "prefix","infix" or "suffix".}
}
\value{
logical vector
}
\description{
Matches pattern to vector based on match type
}
\examples{
c("id", "age", "weight_0", "weight_1") |> grepl_fix(pattern = c("_0", "_1"), type = "suffix")
}

52
man/import-file.Rd Normal file
View file

@ -0,0 +1,52 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import-file-ext.R
\name{import-file}
\alias{import-file}
\alias{import_file_ui}
\alias{import_file_server}
\title{Import data from a file}
\usage{
import_file_ui(
id,
title = TRUE,
preview_data = TRUE,
file_extensions = c(".csv", ".txt", ".xls", ".xlsx", ".rds", ".fst", ".sas7bdat",
".sav"),
layout_params = c("dropdown", "inline")
)
import_file_server(
id,
btn_show_data = TRUE,
show_data_in = c("popup", "modal"),
trigger_return = c("button", "change"),
return_class = c("data.frame", "data.table", "tbl_df", "raw"),
reset = reactive(NULL),
read_fns = list()
)
}
\arguments{
\item{preview_data}{Show or not a preview of the data under the file input.}
\item{file_extensions}{File extensions accepted by \code{\link[shiny:fileInput]{shiny::fileInput()}}, can also be MIME type.}
\item{layout_params}{How to display import parameters : in a dropdown button or inline below file input.}
\item{read_fns}{Named list with custom function(s) to read data:
\itemize{
\item the name must be the extension of the files to which the function will be applied
\item the value must be a function that can have 5 arguments (you can ignore some of them, but you have to use the same names),
passed by user through the interface:
\itemize{
\item \code{file}: path to the file
\item \code{sheet}: for Excel files, sheet to read
\item \code{skip}: number of row to skip
\item \code{dec}: decimal separator
\item \code{encoding}: file encoding
\item \code{na.strings}: character(s) to interpret as missing values.
}
}}
}
\description{
Let user upload a file and import data
}

21
man/import_delim.Rd Normal file
View file

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import-file-ext.R
\name{import_delim}
\alias{import_delim}
\title{Wrapper of data.table::fread to import delim files with few presets}
\usage{
import_delim(file, skip, encoding, na.strings)
}
\arguments{
\item{file}{file}
\item{encoding}{encoding}
\item{na.strings}{na.strings}
}
\value{
data.frame
}
\description{
Wrapper of data.table::fread to import delim files with few presets
}

View file

@ -2,21 +2,26 @@
% Please edit documentation in R/redcap_read_shiny_module.R
\name{is_valid_redcap_url}
\alias{is_valid_redcap_url}
\title{Title}
\title{Test if url is valid format for REDCap API}
\usage{
is_valid_redcap_url(url)
}
\arguments{
\item{url}{}
\item{url}{url}
}
\value{
logical
}
\description{
Title
Test if url is valid format for REDCap API
}
\examples{
url <- c(
"www.example.com",
"http://example.com",
"https://redcap.your.inst/api/"
"redcap.your.inst/api/",
"https://redcap.your.inst/api/",
"https://your.inst/redcap/api/",
"https://www.your.inst/redcap/api/"
)
is_valid_redcap_url(url)
}

View file

@ -11,6 +11,9 @@ is_valid_token(token, pattern_env = NULL, nchar = 32)
\item{pattern_env}{pattern}
}
\value{
logical
}
\description{
Validate REDCap token
}

View file

@ -4,11 +4,23 @@
\alias{line_break}
\title{Line breaking at given number of characters for nicely plotting labels}
\usage{
line_break(data, lineLength = 20)
line_break(data, lineLength = 20, fixed = FALSE)
}
\arguments{
\item{lineLength}{}
\item{data}{string}
\item{lineLength}{maximum line length}
\item{fixed}{flag to force split at exactly the value given in lineLength.
Default is FALSE, only splitting at spaces.}
}
\value{
character string
}
\description{
Line breaking at given number of characters for nicely plotting labels
}
\examples{
"Lorem ipsum... you know the routine" |> line_break()
paste(sample(letters[1:10], 100, TRUE), collapse = "") |> line_break(fixed=TRUE)
}

View file

@ -4,10 +4,15 @@
\alias{plot_sankey_single}
\title{Beautiful sankey plot}
\usage{
plot_sankey_single(data, x, y, color.group = "x", colors = NULL)
plot_sankey_single(data, x, y, color.group = c("x", "y"), colors = NULL, ...)
}
\arguments{
\item{colors}{}
\item{color.group}{set group to colour by. "x" or "y".}
\item{colors}{optinally specify colors. Give NA color, color for each level
in primary group and color for each level in secondary group.}
\item{...}{passed to sankey_ready()}
}
\value{
ggplot2 object

View file

@ -0,0 +1,19 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/redcap_read_shiny_module.R
\name{repeated_instruments}
\alias{repeated_instruments}
\title{Get names of repeated instruments}
\usage{
repeated_instruments(uri, token)
}
\arguments{
\item{uri}{REDCap database uri}
\item{token}{database token}
}
\value{
vector
}
\description{
Get names of repeated instruments
}

View file

@ -1,19 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data_plots.R
\name{sankey_ready}
\alias{sankey_ready}
\title{Readying data for sankey plot}
\usage{
sankey_ready(data, x, y, z = NULL, numbers = "count")
}
\arguments{
\item{z}{}
}
\description{
Readying data for sankey plot
}
\examples{
ds <- data.frame(g = sample(LETTERS[1:2], 100, TRUE), first = REDCapCAST::as_factor(sample(letters[1:4], 100, TRUE)), last = sample(c(letters[1:4], NA), 100, TRUE, prob = c(rep(.23, 4), .08)))
ds |> sankey_ready("first", "last")
ds |> sankey_ready("first", "last", numbers = "percentage")
}

53
man/selectInputIcon.Rd Normal file
View file

@ -0,0 +1,53 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import-file-ext.R
\name{selectInputIcon}
\alias{selectInputIcon}
\title{Create a select input control with icon(s)}
\usage{
selectInputIcon(
inputId,
label,
choices,
selected = NULL,
multiple = FALSE,
selectize = TRUE,
size = NULL,
width = NULL,
icon = NULL
)
}
\arguments{
\item{inputId}{The \code{input} slot that will be used to access the value.}
\item{label}{Display label for the control, or \code{NULL} for no label.}
\item{choices}{List of values to select from. If elements of the list are
named, then that name --- rather than the value --- is displayed to the
user. It's also possible to group related inputs by providing a named list
whose elements are (either named or unnamed) lists, vectors, or factors. In
this case, the outermost names will be used as the group labels (leveraging
the \verb{<optgroup>} HTML tag) for the elements in the respective sublist. See
the example section for a small demo of this feature.}
\item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for
single-select lists and no values for multiple select lists.}
\item{multiple}{Is selection of multiple items allowed?}
\item{selectize}{Whether to use \pkg{selectize.js} or not.}
\item{size}{Number of items to show in the selection box; a larger number
will result in a taller box. Not compatible with \code{selectize=TRUE}.
Normally, when \code{multiple=FALSE}, a select input will be a drop-down list,
but when \code{size} is set, it will be a box instead.}
\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'};
see \code{\link[shiny:validateCssUnit]{validateCssUnit()}}.}
}
\value{
A numeric input control that can be added to a UI definition.
}
\description{
Extend form controls by adding text or icons before,
after, or on both sides of a classic \code{selectInput}.
}

66
man/vectorSelectInput.Rd Normal file
View file

@ -0,0 +1,66 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/custom_SelectInput.R
\name{vectorSelectInput}
\alias{vectorSelectInput}
\title{A selectizeInput customized for named vectors}
\usage{
vectorSelectInput(
inputId,
label,
choices,
selected = "",
...,
placeholder = "",
onInitialize
)
}
\arguments{
\item{inputId}{passed to \code{\link[shiny]{selectizeInput}}}
\item{label}{passed to \code{\link[shiny]{selectizeInput}}}
\item{choices}{A named \code{vector} from which fields should be populated}
\item{selected}{default selection}
\item{...}{passed to \code{\link[shiny]{selectizeInput}}}
\item{placeholder}{passed to \code{\link[shiny]{selectizeInput}} options}
\item{onInitialize}{passed to \code{\link[shiny]{selectizeInput}} options}
}
\value{
a \code{\link[shiny]{selectizeInput}} dropdown element
}
\description{
A selectizeInput customized for named vectors
}
\examples{
if (shiny::interactive()) {
shinyApp(
ui = fluidPage(
shiny::uiOutput("select"),
tableOutput("data")
),
server = function(input, output) {
output$select <- shiny::renderUI({
vectorSelectInput(
inputId = "variable", label = "Variable:",
data = c(
"Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear"
)
)
})
output$data <- renderTable(
{
mtcars[, c("mpg", input$variable), drop = FALSE]
},
rownames = TRUE
)
}
)
}
}

View file

@ -16,7 +16,18 @@ vertical_stacked_bars(
)
}
\arguments{
\item{t.size}{}
\item{data}{data.frame}
\item{score}{outcome variable}
\item{group}{grouping variable}
\item{strata}{stratifying variable}
\item{t.size}{text size}
}
\value{
ggplot2 object
}
\description{
Vertical stacked bar plot wrapper

63
man/wide2long.Rd Normal file
View file

@ -0,0 +1,63 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wide2long.R
\name{wide2long}
\alias{wide2long}
\title{Alternative pivoting method for easily pivoting based on name pattern}
\usage{
wide2long(
data,
pattern,
type = c("prefix", "infix", "suffix"),
id.col = 1,
instance.name = "instance"
)
}
\arguments{
\item{data}{data}
\item{pattern}{pattern(s) to match. Character vector of length 1 or more.}
\item{type}{type of match. can be one of "prefix","infix" or "suffix".}
\item{id.col}{ID column. Will fill ID for all. Column name or numeric index.
Default is "1", first column.}
\item{instance.name}{}
}
\value{
data.frame
}
\description{
This function requires and assumes a systematic naming of variables.
For now only supports one level pivoting. Adding more levels would require
an added "ignore" string pattern or similarly. Example 2.
}
\examples{
data.frame(
1:20, sample(70:80, 20, TRUE),
sample(70:100, 20, TRUE),
sample(70:100, 20, TRUE),
sample(170:200, 20, TRUE)
) |>
setNames(c("id", "age", "weight_0", "weight_1", "height_1")) |>
wide2long(pattern = c("_0", "_1"), type = "suffix")
data.frame(
1:20, sample(70:80, 20, TRUE),
sample(70:100, 20, TRUE),
sample(70:100, 20, TRUE),
sample(170:200, 20, TRUE)
) |>
setNames(c("id", "age", "weight_0", "weight_a_1", "height_b_1")) |>
wide2long(pattern = c("_0", "_1"), type = "suffix")
# Optional filling of missing values by last observation carried forward
# Needed for mmrm analyses
long_missings |>
# Fills record ID assuming none are missing
tidyr::fill(record_id) |>
# Grouping by ID for the last step
dplyr::group_by(record_id) |>
# Filling missing data by ID
tidyr::fill(names(long_missings)[!names(long_missings) \%in\% new_names]) |>
# Remove grouping
dplyr::ungroup()
}