refactor: streamline pad functions

Remove stringr dependency to satisfy R CMD checks
This commit is contained in:
Martin Chan 2022-07-01 13:29:10 +01:00
Родитель df969f4698
Коммит 64dd50ce28
9 изменённых файлов: 85 добавлений и 20 удалений

Просмотреть файл

@ -147,6 +147,7 @@ export(one2one_summary)
export(one2one_trend)
export(p2p_data_sim)
export(p_test)
export(pad2)
export(pairwise_count)
export(period_change)
export(personas_hclust)

Просмотреть файл

@ -151,7 +151,7 @@ plot_flex_index <- function(data,
)
## 00, 01, 02, etc.
hours_col <- stringr::str_pad(seq(0,23), width = 2, pad = 0)
hours_col <- pad2(x = seq(0,23))
# Use `mutate()` method
# Will get 10 IDs, not 10 rows

Просмотреть файл

@ -22,7 +22,6 @@
#' @param legend_text String to be used in the bottom legend label.
#'
#' @param rows Number of rows to show in plot.
#' @noRd
#'
#' @export
@ -41,7 +40,7 @@ plot_hourly_pat <- function(
){
## 00, 01, 02, etc.
hours_col <- stringr::str_pad(seq(0,23), width = 2, pad = 0)
hours_col <- pad2(x = seq(0,23))
data %>%
utils::head(rows) %>%

Просмотреть файл

@ -251,3 +251,19 @@ wrap_text <- function(x, threshold = 15){
x = x
)
}
#' @title
#' Create the two-digit zero-padded format
#'
#' @param x numeric value or vector with maximum two characters.
#'
#' @return
#' Numeric value containing two-digit zero-padded values.
#'
#' @export
pad2 <- function(x){
x <- as.character(x)
ifelse(nchar(x) == 1, paste0("0", x), x)
}

Просмотреть файл

@ -191,14 +191,6 @@ workpatterns_area <- function(data,
mutate(Signals = sub(pattern = "_\\d.+", replacement = "", x = Signals)) %>%
spread(Signals, Value)
## Create the two-digit zero-padded format
## Used in `scale_x_continuous()`
pad2 <- function(x){
x <- as.character(x)
ifelse(nchar(x) == 1, paste0("0", x), x)
}
## Return
if(return == "data"){

Просмотреть файл

@ -295,14 +295,6 @@ plot_signal_clust <- function(data,
mutate_at("Hours", ~sub(pattern = paste0(sig_label, "_"), replacement = "", x = .)) %>%
mutate_at("Hours", ~sub(pattern = "_.+", replacement = "", x = .))
## Create the two-digit zero-padded format
## Used in `scale_x_continuous()`
pad2 <- function(x){
ifelse(nchar(x) == 1,
paste0(0, x),
x)
}
## bar plot
output_bar <-
plot_data %>%

Просмотреть файл

@ -171,7 +171,7 @@ workpatterns_rank <- function(data,
by = num_cols]
## 00, 01, 02, etc.
hours_col <- stringr::str_pad(seq(0,23), width = 2, pad = 0)
hours_col <- pad2(x = seq(0,23))
# Wide table showing proportion of signals by hour
# Ranked descending by `WeekCount`

17
man/pad2.Rd Normal file
Просмотреть файл

@ -0,0 +1,17 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/supporting_functions.R
\name{pad2}
\alias{pad2}
\title{Create the two-digit zero-padded format}
\usage{
pad2(x)
}
\arguments{
\item{x}{numeric value or vector with maximum two characters.}
}
\value{
Numeric value containing two-digit zero-padded values.
}
\description{
Create the two-digit zero-padded format
}

48
man/plot_hourly_pat.Rd Normal file
Просмотреть файл

@ -0,0 +1,48 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/plot_hourly_pat.R
\name{plot_hourly_pat}
\alias{plot_hourly_pat}
\title{Internal function for plotting the hourly activity patterns.}
\usage{
plot_hourly_pat(
data,
start_hour,
end_hour,
legend,
legend_label,
legend_text = "Observed activity",
rows,
title,
subtitle,
caption,
ylab = paste("Top", rows, "activity patterns")
)
}
\arguments{
\item{data}{Data frame containing three columns:
\itemize{
\item \code{patternRank}
\item \code{Hours}
\item \code{Freq}
}}
\item{start_hour}{Numeric value to specify expected start hour.}
\item{end_hour}{Numeric value to specify expected end hour.}
\item{legend}{Data frame containing the columns:
\itemize{
\item \code{patternRank}
\item Any column to be used in the grey label box, supplied to \code{legend_label}
}}
\item{legend_label}{String specifying column to display in the grey label
box}
\item{legend_text}{String to be used in the bottom legend label.}
\item{rows}{Number of rows to show in plot.}
}
\description{
This is used within \code{plot_flex_index()} and \code{workpatterns_rank()}.
}