Skip to content

keep argument for transpose and tstrsplit - #7883

Open
venom1204 wants to merge 5 commits into
masterfrom
issue52500
Open

keep argument for transpose and tstrsplit#7883
venom1204 wants to merge 5 commits into
masterfrom
issue52500

Conversation

@venom1204

Copy link
Copy Markdown
Contributor

closes #5250

This PR implements the keep argument for transpose() and tstrsplit() by moving selective column logic directly into the C engine. By only allocating memory for requested indices in src/transpose.c, the implementation prevents the memory spikes and throwaway column allocations previously associated with subsetting large string-split results.

@venom1204
venom1204 requested review from tdhock and removed request for MichaelChirico August 14, 2026 22:04
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.00%. Comparing base (813ed95) to head (c10f900).

Files with missing lines Patch % Lines
R/transpose.R 90.90% 1 Missing ⚠️
src/transpose.c 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7883      +/-   ##
==========================================
- Coverage   99.01%   99.00%   -0.02%     
==========================================
  Files          88       88              
  Lines       17309    17323      +14     
==========================================
+ Hits        17139    17151      +12     
- Misses        170      172       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
  • HEAD=issue52500 faster P<0.001 for memrecycle regression fixed in #5463
    Comparison Plot

Generated via commit 14cbe56

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 3 minutes and 22 seconds
Installing different package versions 24 seconds
Running and plotting the test cases 5 minutes and 44 seconds

@joshhwuu joshhwuu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took a quick stab. C is not really my forte so I'll leave that up to someone else:)

the PR motivation cites performance benefits. is there some way we can measure this / regression test?

Comment thread man/transpose.Rd
\item{keep.names}{The name of the first column in the result containing the names of the input; e.g. \code{keep.names="rn"}. By default \code{NULL} and the names of the input are discarded.}
\item{make.names}{The name or number of a column in the input to use as names of the output; e.g. \code{make.names="rn"}. By default \code{NULL} and default names are given to the output columns.}
\item{list.cols}{Default is \code{FALSE}. \code{TRUE} will avoid promoting types and return columns of type \code{list} instead. \code{factor} will always be cast to \code{character}.}
\item{keep}{An integer vector of column indices to keep and return. The columns will be returned in the order specified. If \code{NULL} (default), all columns are returned. This is much more memory efficient than transposing the entire list and then subsetting the result.}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more memory efficient than transposing the entire list and then subsetting the result.

not sure if its necessary to justify this use case here

Comment thread man/transpose.Rd
lapply(seq(length(l[[1]])), function(x) lapply(l, `[[`, x))
transpose(l, list.cols=TRUE)

ll = list(nm=c('x', 'y'), 1:2, 3:4)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we remove these examples?

Comment thread R/transpose.R
@@ -1,4 +1,8 @@
transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL, list.cols=FALSE) {
transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL, list.cols=FALSE, keep=NULL) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didnt look but could there be any regressions from folks using keep instead of keep.names explicitly?

Comment thread inst/tests/tests.Rraw

# transpose() supports keep argument, #5250
x = list(1:5, 6:10, 11:15)
test(2388.01, transpose(list(1:5), keep="a"), error="'keep' must be an integer vector.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are tests .01 and .10 not identical?

Comment thread R/transpose.R
transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL, list.cols=FALSE, keep=NULL) {
if (!is.null(keep)) {
if (!is.numeric(keep)) stopf("'keep' must be an integer vector.")
keep = as.integer(keep)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing indent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'keep' argument for tstrsplit?

2 participants