Skip to content

Commit

Permalink
Return all tskit statistics as numerical vectors (not 1D arrays)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Sep 28, 2022
1 parent a6f3242 commit 403df3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

- Avoid the unnecessary `array` type of _tskit_ results returned via reticulate. Numeric vectors (columns of data frames with numerical results) obtained in this way are simple R numeric vector ([#c690334](https://github.com/bodkan/slendr/commit/c690334)).

- One-way and multi-way statistics results are now returned as simple numerical vectors. Previously, results were returned as a type `array` despite "looking" as vectors (this is how values are returned to R from the reticulate-Python layer), which caused unnecessary annoyances and type-conversions on the R side of things and was not even intended ([#e1d178e](https://github.com/bodkan/slendr/commit/e1d178e)).

# slendr 0.3.0

- SLiM 4.0 is now required for running simulations with the `slim()` engine. If you want to run _slendr_ simulations with SLiM (spatial or non-spatial), you will need to upgrade you SLiM installation. SLiM 3.7.1 version is no longer supported as the upcoming new _slendr_ spatial features will depend on SLiM 4.x and maintaining two functionally identical yet syntactically different back ends is not feasible (PR [#104](https://github.com/bodkan/slendr/pull/104)).
Expand Down
8 changes: 6 additions & 2 deletions R/tree-sequences.R
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,8 @@ multiway_stat <- function(ts, stat = c("fst", "divergence"),
if (is.matrix(values))
values <- split(values, col(values))

if (!is.list(values)) values <- as.numeric(values) # convert 1D arrays to simple vectors

if (is.null(names(sample_sets)))
set_names <- paste0("set_", seq_len(n_sets))
else
Expand All @@ -1677,7 +1679,7 @@ multiway_stat <- function(ts, stat = c("fst", "divergence"),
as.data.frame(t(matrix(set)), stringsAsFactors = FALSE)
}) %>%
dplyr::as_tibble() %>%
dplyr::mutate(stat = as.numeric(values))
dplyr::mutate(stat = values)

result
}
Expand Down Expand Up @@ -1786,6 +1788,8 @@ oneway_stat <- function(ts, stat, sample_sets, mode, windows, span_normalise = N
if (is.matrix(values))
values <- split(values, col(values))

if (!is.list(values)) values <- as.numeric(values) # convert 1D arrays to simple vectors

if (all(sapply(sample_sets, length) == 1))
set_names <- unlist(sample_sets)
else if (is.null(names(sample_sets)))
Expand All @@ -1794,7 +1798,7 @@ oneway_stat <- function(ts, stat, sample_sets, mode, windows, span_normalise = N
set_names <- names(sample_sets)

result <- dplyr::tibble(set = set_names)
result[[stat]] <- as.numeric(values)
result[[stat]] <- values
result
}

Expand Down

0 comments on commit 403df3b

Please sign in to comment.