-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Read trait-wise data | ||
#' | ||
#' Wrapper around \code{read_speciome} for variables with one value per | ||
#' trait per time point. | ||
#' | ||
#' @param root Path to the simulation folder | ||
#' @param variables Vector of names of variable to read (will be interpreted using \code{interpret_variable_names}) | ||
#' | ||
#' @return A tibble containing the simulation data | ||
#' | ||
#' @note The function will read "time.dat" as an extra variable, no need to | ||
#' supply it. | ||
#' | ||
#' @seealso \code{read_speciome} | ||
#' | ||
#' @examples | ||
#' | ||
#' root <- system.file("extdata", "sim-example", package = "speciomer") | ||
#' read_traits(root, "trait_Fst") | ||
#' | ||
#' @export | ||
|
||
read_traits <- function(root, variables) { | ||
|
||
# Add a trait prefix to the variable names if needed | ||
variables <- interpret_variable_names(variables, type = "trait") | ||
|
||
# Parametrization | ||
ncols <- rep(1, length(variables)) | ||
variables <- c("time", variables) | ||
ncols <- c(-3, ncols) | ||
|
||
# Read trait-wise data | ||
data <- read_speciome(root, variables, ncols = ncols) | ||
|
||
# Remove the prefix "trait", now redundant | ||
colnames(data) <- stringr::str_remove(colnames(data), "trait_") | ||
|
||
# Add a trait identifier | ||
data <- data %>% | ||
tibble::add_column(trait = rep(seq(3), nrow(data) / 3), .after = "time") | ||
|
||
return(data) | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root <- system.file("extdata", "sim-example", package = "speciomer") | ||
|
||
test_that("Read trait-wise data", { | ||
|
||
data <- read_traits(root, "Cst") | ||
ntimes <- length(read_binary(paste0(root, "/time.dat"))) | ||
expect_equal(nrow(data), 3 * ntimes) | ||
|
||
}) |