renaming to cut function to cut_var to distinct from the base-version - UI improvements - nice code formatting.

This commit is contained in:
Andreas Gammelgaard Damsbo 2025-04-11 13:23:18 +02:00
commit 361296531e
No known key found for this signature in database
30 changed files with 1248 additions and 1686 deletions

28
man/append_column.Rd Normal file
View file

@ -0,0 +1,28 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{append_column}
\alias{append_column}
\title{Append a column to a data.frame}
\usage{
append_column(data, column, name, index = "right")
}
\arguments{
\item{data}{data}
\item{column}{new column (vector) or data.frame with 1 column}
\item{name}{new name (pre-fix)}
\item{index}{desired location. May be "left", "right" or numeric index.}
}
\value{
data.frame
}
\description{
Append a column to a data.frame
}
\examples{
mtcars |>
dplyr::mutate(mpg_cut = mpg) |>
append_column(mtcars$mpg, "mpg_cutter")
}

View file

@ -1,15 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cut-variable-dates.R
\name{cut.hms}
\alias{cut.hms}
\alias{cut.POSIXt}
\alias{cut.POSIXct}
\alias{cut.Date}
\title{Extended cutting function}
\name{cut_var}
\alias{cut_var}
\alias{cut_var.default}
\alias{cut_var.hms}
\alias{cut_var.POSIXt}
\alias{cut_var.POSIXct}
\alias{cut_var.Date}
\title{Extended cutting function with fall-back to the native base::cut}
\usage{
\method{cut}{hms}(x, breaks, ...)
cut_var(x, ...)
\method{cut}{POSIXt}(
\method{cut_var}{default}(x, ...)
\method{cut_var}{hms}(x, breaks, ...)
\method{cut_var}{POSIXt}(
x,
breaks,
right = FALSE,
@ -18,7 +24,7 @@
...
)
\method{cut}{POSIXct}(
\method{cut_var}{POSIXct}(
x,
breaks,
right = FALSE,
@ -27,7 +33,7 @@
...
)
\method{cut}{Date}(x, breaks, start.on.monday = TRUE, ...)
\method{cut_var}{Date}(x, breaks, start.on.monday = TRUE, ...)
}
\arguments{
\item{x}{an object inheriting from class "POSIXct"}
@ -38,19 +44,19 @@
factor
}
\description{
Extended cutting function
Extended cutting function with fall-back to the native base::cut
}
\examples{
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut(2)
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut("min")
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut(breaks = "hour")
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut(breaks = hms::as_hms(c("01:00:00", "03:01:20", "9:20:20")))
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut_var(2)
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut_var("min")
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut_var(breaks = "hour")
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "08:20:20", "21:20:20", "03:02:20")) |> cut_var(breaks = hms::as_hms(c("01:00:00", "03:01:20", "9:20:20")))
d_t <- readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "03:02:20", NA))
f <- d_t |> cut(2)
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "03:02:20", NA)) |> cut(breaks = lubridate::as_datetime(c(hms::as_hms(levels(f)), hms::as_hms(max(d_t, na.rm = TRUE) + 1))), right = FALSE)
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut(2)
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut(breaks="weekday")
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut(breaks="month_only")
as.Date(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut(2)
as.Date(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut(breaks="weekday")
f <- d_t |> cut_var(2)
readr::parse_time(c("01:00:20", "03:00:20", "01:20:20", "03:02:20", NA)) |> cut_var(breaks = lubridate::as_datetime(c(hms::as_hms(levels(f)), hms::as_hms(max(d_t, na.rm = TRUE) + 1))), right = FALSE)
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut_var(2)
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut_var(breaks = "weekday")
readr::parse_datetime(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut_var(breaks = "month_only")
as.Date(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut_var(2)
as.Date(c("1992-02-01 01:00:20", "1992-02-06 03:00:20", "1992-05-01 01:20:20", "1992-09-01 08:20:20", "1999-02-01 21:20:20", "1992-12-01 03:02:20")) |> cut_var(breaks = "weekday")
}

View file

@ -20,4 +20,9 @@ mtcars |> str()
mtcars |>
default_parsing() |>
str()
head(starwars, 5) |> str()
starwars |>
default_parsing() |>
head(5) |>
str()
}

View file

@ -4,7 +4,7 @@
\alias{expression_string}
\title{Deparses expression as string, substitutes native pipe and adds assign}
\usage{
expression_string(data, assign.str = "data <- ")
expression_string(data, assign.str = "")
}
\arguments{
\item{data}{expression}
@ -17,7 +17,9 @@ Deparses expression as string, substitutes native pipe and adds assign
}
\examples{
list(
rlang::call2(.fn = "select",!!!list(c("cyl","disp")),.ns = "dplyr"),
rlang::call2(.fn = "default_parsing",.ns = "FreesearchR")
) |> merge_expression() |> expression_string()
rlang::call2(.fn = "select", !!!list(c("cyl", "disp")), .ns = "dplyr"),
rlang::call2(.fn = "default_parsing", .ns = "FreesearchR")
) |>
merge_expression() |>
expression_string()
}

View file

@ -19,6 +19,6 @@ Return if available
}
\examples{
NULL |> if_not_missing("new")
c(2,"a",NA) |> if_not_missing()
c(2, "a", NA) |> if_not_missing()
"See" |> if_not_missing()
}

View file

@ -1,17 +0,0 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/file-import-module.R
\name{m_datafileUI}
\alias{m_datafileUI}
\title{Shiny UI module to load a data file}
\usage{
m_datafileUI(id)
}
\arguments{
\item{id}{id}
}
\value{
shiny UI
}
\description{
Shiny UI module to load a data file
}

View file

@ -17,7 +17,7 @@ Merge list of expressions
}
\examples{
list(
rlang::call2(.fn = "select",!!!list(c("cyl","disp")),.ns = "dplyr"),
rlang::call2(.fn = "default_parsing",.ns = "FreesearchR")
rlang::call2(.fn = "select", !!!list(c("cyl", "disp")), .ns = "dplyr"),
rlang::call2(.fn = "default_parsing", .ns = "FreesearchR")
) |> merge_expression()
}

27
man/pipe_string.Rd Normal file
View file

@ -0,0 +1,27 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{pipe_string}
\alias{pipe_string}
\title{Reduce character vector with the native pipe operator or character string}
\usage{
pipe_string(data, collapse = "|>\\n")
}
\arguments{
\item{data}{list}
}
\value{
character string
}
\description{
Reduce character vector with the native pipe operator or character string
}
\examples{
list(
"mtcars",
rlang::call2(.fn = "select", !!!list(c("cyl", "disp")), .ns = "dplyr"),
rlang::call2(.fn = "default_parsing", .ns = "FreesearchR")
) |>
lapply(expression_string) |>
pipe_string() |>
expression_string("data<-")
}

17
man/remove_empty_attr.Rd Normal file
View file

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{remove_empty_attr}
\alias{remove_empty_attr}
\title{Remove empty/NA attributes}
\usage{
remove_empty_attr(data)
}
\arguments{
\item{data}{data}
}
\value{
data of same class as input
}
\description{
Remove empty/NA attributes
}

21
man/remove_nested_list.Rd Normal file
View file

@ -0,0 +1,21 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{remove_nested_list}
\alias{remove_nested_list}
\title{Very simple function to remove nested lists, lik ewhen uploading .rds}
\usage{
remove_nested_list(data)
}
\arguments{
\item{data}{data}
}
\value{
data.frame
}
\description{
Very simple function to remove nested lists, lik ewhen uploading .rds
}
\examples{
dplyr::tibble(a = 1:10, b = rep(list("a"), 10)) |> remove_nested_list()
dplyr::tibble(a = 1:10, b = rep(list(c("a", "b")), 10)) |> as.data.frame()
}

29
man/set_column_label.Rd Normal file
View file

@ -0,0 +1,29 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{set_column_label}
\alias{set_column_label}
\title{(Re)label columns in data.frame}
\usage{
set_column_label(data, label, overwrite = TRUE)
}
\arguments{
\item{data}{data.frame to be labelled}
\item{label}{named list or vector}
}
\value{
data.frame
}
\description{
(Re)label columns in data.frame
}
\examples{
ls <- list("mpg" = "", "cyl" = "Cylinders", "disp" = "", "hp" = "", "drat" = "", "wt" = "", "qsec" = "", "vs" = "", "am" = "", "gear" = "", "carb" = "")
ls2 <- c("mpg" = "", "cyl" = "Cylinders", "disp" = "", "hp" = "Horses", "drat" = "", "wt" = "", "qsec" = "", "vs" = "", "am" = "", "gear" = "", "carb" = "")
ls3 <- c("mpg" = "", "cyl" = "", "disp" = "", "hp" = "Horses", "drat" = "", "wt" = "", "qsec" = "", "vs" = "", "am" = "", "gear" = "", "carb" = "")
mtcars |>
set_column_label(ls) |>
set_column_label(ls2) |>
set_column_label(ls3)
rlang::expr(FreesearchR::set_column_label(label = !!ls3)) |> expression_string()
}

View file

@ -22,5 +22,5 @@ vector
Drop-in replacement for the base::sort_by with option to remove NAs
}
\examples{
sort_by(c("Multivariable", "Univariable"),c("Univariable","Minimal","Multivariable"))
sort_by(c("Multivariable", "Univariable"), c("Univariable", "Minimal", "Multivariable"))
}