sample_n() and sample_frac() have been superseded in favour of
slice_sample(). While they will not be deprecated in the near future,
retirement means that we will only perform critical bug fixes, so we recommend
moving to the newer alternative.
These functions were superseded because we realised it was more convenient to
have two mutually exclusive arguments to one function, rather than two
separate functions. This also made it to clean up a few other smaller
design issues with sample_n()/sample_frac:
The connection to slice() was not obvious.
The name of the first argument, tbl, is inconsistent with other
single table verbs which use .data.
The size argument uses tidy evaluation, which is surprising and
undocumented.
It was easier to remove the deprecated .env argument.
... was in a suboptimal position.
# S3 method for class 'SummarizedExperiment'
sample_n(tbl, size, replace = FALSE, weight = NULL, .env = NULL, ...)
# S3 method for class 'SummarizedExperiment'
sample_frac(tbl, size = 1, replace = FALSE, weight = NULL, .env = NULL, ...)A data.frame.
<tidy-select>
For sample_n(), the number of rows to select.
For sample_frac(), the fraction of rows to select.
If tbl is grouped, size applies to each group.
Sample with or without replacement?
<tidy-select> Sampling weights.
This must evaluate to a vector of non-negative numbers the same length as
the input. Weights are automatically standardised to sum to 1.
DEPRECATED.
ignored
tidySummarizedExperiment
Hutchison, W.J., Keyes, T.J., The tidyomics Consortium. et al. The tidyomics ecosystem: enhancing omic data analyses. Nat Methods 21, 1166–1170 (2024). https://doi.org/10.1038/s41592-024-02299-2
Wickham, H., François, R., Henry, L., Müller, K., Vaughan, D. (2023). dplyr: A Grammar of Data Manipulation. R package version 2.1.4, https://CRAN.R-project.org/package=dplyr
Hutchison, W.J., Keyes, T.J., The tidyomics Consortium. et al. The tidyomics ecosystem: enhancing omic data analyses. Nat Methods 21, 1166–1170 (2024). https://doi.org/10.1038/s41592-024-02299-2
Wickham, H., François, R., Henry, L., Müller, K., Vaughan, D. (2023). dplyr: A Grammar of Data Manipulation. R package version 2.1.4, https://CRAN.R-project.org/package=dplyr
data(pasilla)
pasilla |> sample_n(50)
#> tidySummarizedExperiment says: A data frame is returned for independent data analysis.
#> # A tibble: 50 × 5
#> .feature .sample counts condition type
#> <chr> <chr> <int> <chr> <chr>
#> 1 FBgn0043069 untrt4 0 untreated paired_end
#> 2 FBgn0027793 trt2 30 treated paired_end
#> 3 FBgn0011766 untrt3 4151 untreated paired_end
#> 4 FBgn0031320 untrt2 288 untreated single_end
#> 5 FBgn0034915 untrt4 827 untreated paired_end
#> 6 FBgn0030768 trt2 665 treated paired_end
#> 7 FBgn0034292 untrt2 0 untreated single_end
#> 8 FBgn0053817 untrt1 0 untreated single_end
#> 9 FBgn0030998 untrt1 3 untreated single_end
#> 10 FBgn0003511 untrt4 276 untreated paired_end
#> # ℹ 40 more rows
pasilla |> sample_frac(0.1)
#> tidySummarizedExperiment says: A data frame is returned for independent data analysis.
#> # A tibble: 10,219 × 5
#> .feature .sample counts condition type
#> <chr> <chr> <int> <chr> <chr>
#> 1 FBgn0037461 untrt3 0 untreated paired_end
#> 2 FBgn0011906 untrt2 0 untreated single_end
#> 3 FBgn0010812 trt1 1736 treated single_end
#> 4 FBgn0035065 trt1 409 treated single_end
#> 5 FBgn0050418 untrt1 6 untreated single_end
#> 6 FBgn0038828 trt1 22 treated single_end
#> 7 FBgn0036706 trt2 1 treated paired_end
#> 8 FBgn0260953 untrt1 0 untreated single_end
#> 9 FBgn0034827 trt2 0 treated paired_end
#> 10 FBgn0260748 trt2 3138 treated paired_end
#> # ℹ 10,209 more rows