Skip to content

Commit

Permalink
apply styler
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Sep 20, 2023
1 parent c0c64a2 commit 9c8cfc7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
6 changes: 3 additions & 3 deletions R/generate_dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#'
#' @param num_rows Number of rows to generate
#' @param types Types of columns to generate
#'
#'
#' @return A dataframe with the generated columns
#'
#'
#' @examples
#' generate_dataframe(10L)
generate_dataframe <- function(num_rows, types = names(vector_generators)) {
types <- match.arg(types)
data <- lapply(types, generate_vector, n = num_rows)
names(data) <- types
as.data.frame(data)
}
}
36 changes: 17 additions & 19 deletions R/generate_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
#' @param ... Arguments passed to generate_dataset_as_list
#'
#' @return Object containing the generated dataset as defined by `output`
#'
#'
#' @noRd
#'
#' @examples
#' dummy <- generate_dataset()
generate_dataset <- function(
n_obs = 10L,
n_vars = 20L,
format = c("list", "SingleCellExperiment", "Seurat"),
...
) {
n_obs = 10L,
n_vars = 20L,
format = c("list", "SingleCellExperiment", "Seurat"),
...) {
format <- match.arg(format)

fun <- switch(format,
Expand All @@ -39,20 +38,19 @@ generate_dataset <- function(
#' @param n_vars Number of variables to generate
#'
#' @return A list with the generated dataset
#'
#'
#' @noRd
generate_dataset_as_list <- function(
n_obs = 10L,
n_vars = 20L,
x_type = names(matrix_generators)[[1]],
layer_types = names(matrix_generators),
obs_types = names(vector_generators),
var_types = names(vector_generators),
obsm_types = c(names(matrix_generators), names(vector_generators)),
varm_types = c(names(matrix_generators), names(vector_generators)),
obsp_types = names(matrix_generators),
varp_types = names(matrix_generators)
) {
n_obs = 10L,
n_vars = 20L,
x_type = names(matrix_generators)[[1]],
layer_types = names(matrix_generators),
obs_types = names(vector_generators),
var_types = names(vector_generators),
obsm_types = c(names(matrix_generators), names(vector_generators)),
varm_types = c(names(matrix_generators), names(vector_generators)),
obsp_types = names(matrix_generators),
varp_types = names(matrix_generators)) {
# generate X
X <- generate_matrix(n_obs, n_vars, x_type)

Expand Down Expand Up @@ -147,7 +145,7 @@ generate_dataset_as_list <- function(
#' @param ... Parameters passed to `generate_dataset_as_list`
#'
#' @return SingleCellExperiment containing the generated data
#'
#'
#' @noRd
generate_dataset_as_sce <- function(...) {
if (!requireNamespace("SingleCellExperiment", quietly = TRUE)) {
Expand Down
12 changes: 6 additions & 6 deletions R/generate_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ matrix_generators <- list(
)

#' Generate a matrix
#'
#'
#' Generate a matrix of a given type
#'
#'
#' @param n_obs Number of observations to generate
#' @param n_vars Number of variables to generate
#'
#'
#' @return A matrix of the given type
#'
#'
#' @noRd
#'
#'
#' @examples
#' generate_matrix(10L, 20L)
generate_matrix <- function(n_obs, n_vars, type = names(matrix_generators)) {
type <- match.arg(type)
matrix_generators[[type]](n_obs, n_vars)
}
}
12 changes: 6 additions & 6 deletions R/generate_vector.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ vector_generators <- list(
)

#' Generate a vector
#'
#'
#' Generate a vector of a given type
#'
#'
#' @param n Number of elements to generate
#' @param type Type of vector to generate
#'
#'
#' @return A vector of the given type
#'
#'
#' @noRd
#'
#'
#' @examples
#' generate_vector(10L)
generate_vector <- function(n, type = names(vector_generators)) {
type <- match.arg(type)
vector_generators[[type]](n)
}
}

0 comments on commit 9c8cfc7

Please sign in to comment.