Skip to content

Commit

Permalink
[write] table column names have to be characters
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 2, 2024
1 parent 7c94ede commit f04f5ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void wide_to_long(

int8_t vtyp = (int8_t)vtyps[i];
// if colname is provided, the first row is always a character
if (ColNames & (j == 0)) vtyp = character;
if (ColNames && (j == 0)) vtyp = character;
std::string vals = Rcpp::as<std::string>(cvec[j]);
std::string row = std::to_string(startrow);

Expand Down Expand Up @@ -551,7 +551,7 @@ void wide_to_long(
case character:

// test if string can be written as number
if (string_nums && is_double(vals)) {
if (!(ColNames && (j == 0)) && string_nums && is_double(vals)) {
cell.v = vals;
if (string_nums == 1) {
vtyp = string_num;
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,23 @@ test_that("updating table works", {
expect_equal(got, "A1:J4")

})

test_that("writing table with factor titles works", {
df <- data.frame(
fct = structure(
1:2,
levels = c(
"one",
"two"
),
class = "factor"),
`1` = 1:2,
check.names = F

Check warning on line 217 in tests/testthat/test-tables.R

View workflow job for this annotation

GitHub Actions / lint

file=tests/testthat/test-tables.R,line=217,col=20,[T_and_F_symbol_linter] Use FALSE instead of the symbol F.
)

wb <- wb_workbook()$add_worksheet()$add_data_table(x = df)

exp <- "<is><t>1</t></is>"
got <- wb$worksheets[[1]]$sheet_data$cc$is[[2]]
expect_equal(exp, got)
})

0 comments on commit f04f5ee

Please sign in to comment.