write_hrc2() fails when the first column contains a single value (e.g. a total column)

Open Beginner friendly
#63 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
data

Research direction

Start in R/writehrc.R at write_hrc2(), using the reproducible corr_table example from the issue. Inspect how d is used after a single-valued first column is removed, then verify the function succeeds with both sort_table = TRUE and sort_table = FALSE and produces the expected HRC output.

Written by the indexing model from the issue text.

Description

The issue occurs in the write_hrc2() function in R/writehrc.R.

Reproducible example
corr_table <- data.frame(
  niveau1 = c("Total", "Total", "Total"),
  niveau2 = c("A", "A", "B"),
  niveau3 = c("A1", "A2", "B1")
)

write_hrc2(
  corr_table = corr_table,
  file_name = tempfile(fileext = ".hrc"),
  sort_table = TRUE
)
Error
Error in Ops.data.frame(corr_table, corr_table_dec_left) :
  ‘==’ only defined for equally-sized data frames

The same error occurs with sort_table = FALSE.

Possible cause

d is computed before the first column is removed:

d <- dim.data.frame(corr_table)

if (length(unique(as.character(corr_table[,1]))) == 1) {
  corr_table <- corr_table[,-1]
}

After removing the column, d is no longer consistent with corr_table.

A possible fix:

if (length(unique(as.character(corr_table[,1]))) == 1) {
  corr_table <- corr_table[,-1]
  d <- dim.data.frame(corr_table)
}
Dominant language
HTML
Stars
11
Forks
5
Avg merge
1m
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from InseeFrLab/rtauargus

All issues in InseeFrLab/rtauargus

Similar issues

More Data Engineering issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.