Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: single-column data frame input for row_to_names() now works #545

Merged
merged 8 commits into from
May 30, 2023

Conversation

matanhakim
Copy link
Contributor

Description

Before this PR and after merging #542, code like this would error:

library(janitor)
df <- data.frame(x = c("", "", "", "1"))

df |>
  row_to_names(1:3) |> 
  names()

this is because in the code:

new_names <- sapply(dat[row_number,], paste_skip_na, collapse = sep) %>% 
    stringr::str_replace_na()

the specific call dat[row_number,] turns the single-column data frame (i.e., a list of length 1) to a character vector (of length 3 in this case). This, in turn, makes sapply() to iterate over a wrong vector and therefore error.

Changing this to dat[row_number, , drop = FALSE] solves this.

A relevant test was added to prevent this in the future.

Finally, documentation for the changed behavior of the row_number argument in row_to_names() was added, and the NEWS file was edited to reflect changes in this PR and in #542.

Related Issue

Fixes #536 and follows up on #542.

Example

See above.

@codecov
Copy link

codecov bot commented May 27, 2023

Codecov Report

Merging #545 (555eceb) into main (5a34f00) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #545   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         1182      1182           
=========================================
  Hits          1182      1182           
Impacted Files Coverage Δ
R/row_to_names.R 100.00% <100.00%> (ø)

@billdenney billdenney merged commit 8b98f09 into sfirke:main May 30, 2023
9 checks passed
@billdenney
Copy link
Collaborator

This looks good. Thanks!

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.

Feature suggestion: allow multiple rows input to row_to_names()
2 participants