diff --git a/R/class-sheet-data.R b/R/class-sheet-data.R
index 792234b06..1cd750199 100644
--- a/R/class-sheet-data.R
+++ b/R/class-sheet-data.R
@@ -34,16 +34,6 @@ wb_sheet_data <- function() {
# helpers -----------------------------------------------------------------
-# Consider making some helpers for the cc stuff.
-
-empty_sheet_data_cc <- function(n) {
- create_char_dataframe(
- colnames = c("r", "row_r", "c_r", "c_s", "c_t", "c_cm", "c_ph", "c_vm",
- "v", "f", "f_attr", "is", "typ"),
- n = n
- )
-}
-
empty_row_attr <- function(n) {
create_char_dataframe(
colnames = c("collapsed", "customFormat", "customHeight", "x14ac:dyDescent",
diff --git a/R/class-workbook.R b/R/class-workbook.R
index cf48990b8..d255c36d2 100644
--- a/R/class-workbook.R
+++ b/R/class-workbook.R
@@ -4042,7 +4042,7 @@ wbWorkbook <- R6::R6Class(
if (as_ref) {
from_sheet_name <- self$get_sheet_names(escape = TRUE)[[from_sheet]]
- to_cc[c("c_t", "c_cm", "c_ph", "c_vm", "v", "f", "f_attr", "is")] <- ""
+ to_cc[names(to_cc) %in% c("c_t", "c_cm", "c_ph", "c_vm", "v", "f", "f_attr", "is")] <- ""
to_cc[c("f")] <- paste0(shQuote(from_sheet_name, type = "sh"), "!", from_dims)
}
diff --git a/R/class-worksheet.R b/R/class-worksheet.R
index e7e80da68..19f00f046 100644
--- a/R/class-worksheet.R
+++ b/R/class-worksheet.R
@@ -638,10 +638,10 @@ wbWorksheet <- R6::R6Class(
if (characters)
cc[sel & cc$c_t %in% c("inlineStr", "s", "str"),
- c("c_t", "c_ph", "v", "f", "f_attr", "is")] <- ""
+ names(cc) %in% c("c_t", "c_ph", "v", "f", "f_attr", "is")] <- ""
if (styles)
- cc[sel, c("c_s", "c_cm", "c_vm")] <- ""
+ cc[sel, names(cc) %in% c("c_s", "c_cm", "c_vm")] <- ""
self$sheet_data$cc <- cc
diff --git a/R/write.R b/R/write.R
index 790be5408..fc3909875 100644
--- a/R/write.R
+++ b/R/write.R
@@ -90,15 +90,11 @@ inner_update <- function(
na.strings <- NULL
}
- if (removeCellStyle) {
- cell_style <- "c_s"
- } else {
- cell_style <- NULL
+ replacement <- names(cc)
+ if (!removeCellStyle) {
+ replacement <- replacement[-which(replacement == "c_s")]
}
- replacement <- c("r", cell_style, "c_t", "c_cm", "c_ph", "c_vm", "v",
- "f", "f_attr", "is", "typ")
-
sel <- match(x$r, cc$r)
# to avoid bricking the worksheet, we make sure that we do not overwrite the
@@ -148,9 +144,10 @@ inner_update <- function(
initialize_cell <- function(wb, sheet, new_cells) {
sheet_id <- wb$validate_sheet(sheet)
+ nms <- names(wb$worksheets[[sheet_id]]$sheet_data$cc)
# create artificial cc for the missing cells
- x <- empty_sheet_data_cc(n = length(new_cells))
+ x <- create_char_dataframe(n = length(new_cells), colnames = nms)
x$r <- new_cells
x$row_r <- gsub("[[:upper:]]", "", new_cells)
x$c_r <- gsub("[[:digit:]]", "", new_cells)
@@ -417,8 +414,15 @@ write_data2 <- function(
rows_attr$r <- rownames(rtyp)
# original cc data frame
- cc <- empty_sheet_data_cc(n = nrow(data) * ncol(data))
-
+ has_cm <- if (any(dc == openxlsx2_celltype[["cm_formula"]])) "c_cm" else NULL
+ nms <- c(
+ "r", "row_r", "c_r", "c_s", "c_t", has_cm,
+ "v", "f", "f_attr", "is", "typ"
+ )
+ cc <- create_char_dataframe(
+ colnames = nms,
+ n = nrow(data) * ncol(data)
+ )
sel <- which(dc == openxlsx2_celltype[["logical"]])
for (i in sel) {
@@ -524,13 +528,14 @@ write_data2 <- function(
int_si <- max(int_si, -1L) + 1L
- cc$f_attr <- sprintf("t=\"%s\"", "shared")
+ cc[["f_attr"]] <- sprintf("t=\"%s\"", "shared")
cc[1, "f_attr"] <- paste(cc[1, "f_attr"], sprintf("ref=\"%s\"", dims))
+ cc[["f_attr"]] <- paste(cc[["f_attr"]], sprintf("si=\"%s\"", int_si))
cc[2:nrow(cc), "f"] <- ""
- cc$f_attr <- paste(cc$f_attr, sprintf("si=\"%s\"", int_si))
}
if (is.null(wb$worksheets[[sheetno]]$sheet_data$cc)) {
+ # message("write_cell()")
wb$worksheets[[sheetno]]$dimension <- paste0("")
diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp
index 55675e872..7ce191f5f 100644
--- a/src/helper_functions.cpp
+++ b/src/helper_functions.cpp
@@ -397,10 +397,14 @@ void wide_to_long(
int32_t in_string_nums = string_nums;
+ bool has_cm = zz.containsElementNamed("c_cm");
+
// pointer magic. even though these are extracted, they just point to the
// memory in the data frame
+ Rcpp::CharacterVector zz_c_cm;
+
Rcpp::CharacterVector zz_row_r = Rcpp::as(zz["row_r"]);
- Rcpp::CharacterVector zz_c_cm = Rcpp::as(zz["c_cm"]);
+ if (has_cm) zz_c_cm = Rcpp::as(zz["c_cm"]);
Rcpp::CharacterVector zz_c_r = Rcpp::as(zz["c_r"]);
Rcpp::CharacterVector zz_v = Rcpp::as(zz["v"]);
Rcpp::CharacterVector zz_c_t = Rcpp::as(zz["c_t"]);
diff --git a/src/load_workbook.cpp b/src/load_workbook.cpp
index f7e2a4399..22fd00d7c 100644
--- a/src/load_workbook.cpp
+++ b/src/load_workbook.cpp
@@ -160,6 +160,8 @@ inline Rcpp::DataFrame row_to_df(XPtrXML doc) {
void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
auto ws = doc->child("worksheet").child("sheetData");
+ bool has_cm = false, has_ph = false, has_vm = false;
+
// character
Rcpp::DataFrame row_attributes;
@@ -228,9 +230,18 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
if (attr_name == s_str) single_xml_col.c_s = buffer;
if (attr_name == t_str) single_xml_col.c_t = buffer;
- if (attr_name == cm_str) single_xml_col.c_cm = buffer;
- if (attr_name == ph_str) single_xml_col.c_ph = buffer;
- if (attr_name == vm_str) single_xml_col.c_vm = buffer;
+ if (attr_name == cm_str) {
+ has_cm = true;
+ single_xml_col.c_cm = buffer;
+ }
+ if (attr_name == ph_str) {
+ has_ph = true;
+ single_xml_col.c_ph = buffer;
+ }
+ if (attr_name == vm_str) {
+ has_vm = true;
+ single_xml_col.c_vm = buffer;
+ }
}
// some files have no colnames. in this case we need to add c_r and row_r
@@ -283,6 +294,8 @@ void loadvals(Rcpp::Environment sheet_data, XPtrXML doc) {
++itr_rows;
}
+ // Rcpp::Rcout << has_cm << ": " << has_ph << ": " << has_vm << std::endl;
+
sheet_data["row_attr"] = row_attributes;
- sheet_data["cc"] = Rcpp::wrap(xml_cols);
+ sheet_data["cc"] = xml_cols_to_df(xml_cols, has_cm, has_ph, has_vm);
}
diff --git a/src/openxlsx2.h b/src/openxlsx2.h
index d19f23325..6bc9aabf7 100644
--- a/src/openxlsx2.h
+++ b/src/openxlsx2.h
@@ -121,3 +121,184 @@ static inline bool validate_dims(const std::string& input) {
return has_col && has_row;
}
+
+inline SEXP xml_cols_to_df(const std::vector& x, bool has_cm, bool has_ph, bool has_vm) {
+ R_xlen_t n = static_cast(x.size());
+
+ // Vector structure identical to xml_col from openxlsx2_types.h
+ Rcpp::CharacterVector r(Rcpp::no_init(n)); // cell name: A1, A2 ...
+ Rcpp::CharacterVector row_r(Rcpp::no_init(n)); // row name: 1, 2, ..., 9999
+
+ Rcpp::CharacterVector c_r(Rcpp::no_init(n)); // col name: A, B, ..., ZZ
+ Rcpp::CharacterVector c_s(Rcpp::no_init(n)); // cell style
+ Rcpp::CharacterVector c_t(Rcpp::no_init(n)); // cell type
+ Rcpp::CharacterVector c_cm, c_ph, c_vm;
+ if (has_cm) c_cm = Rcpp::CharacterVector(Rcpp::no_init(n));
+ if (has_ph) c_ph = Rcpp::CharacterVector(Rcpp::no_init(n));
+ if (has_vm) c_vm = Rcpp::CharacterVector(Rcpp::no_init(n));
+
+ Rcpp::CharacterVector v(Rcpp::no_init(n)); // tag
+ Rcpp::CharacterVector f(Rcpp::no_init(n)); // tag
+ Rcpp::CharacterVector f_attr(Rcpp::no_init(n)); // attributes
+ Rcpp::CharacterVector is(Rcpp::no_init(n)); // tag
+
+ // struct to vector
+ // We have to convert utf8 inputs via Rcpp::String for non unicode R sessions
+ // Ideally there would be a function that calls Rcpp::String only if needed
+ for (R_xlen_t i = 0; i < n; ++i) {
+ size_t ii = static_cast(i);
+ if (!x[ii].r.empty()) r[i] = std::string(x[ii].r);
+ if (!x[ii].row_r.empty()) row_r[i] = std::string(x[ii].row_r);
+ if (!x[ii].c_r.empty()) c_r[i] = std::string(x[ii].c_r);
+ if (!x[ii].c_s.empty()) c_s[i] = std::string(x[ii].c_s);
+ if (!x[ii].c_t.empty()) c_t[i] = std::string(x[ii].c_t);
+ if (has_cm && !x[ii].c_cm.empty()) c_cm[i] = std::string(x[ii].c_cm);
+ if (has_ph && !x[ii].c_ph.empty()) c_ph[i] = Rcpp::String(x[ii].c_ph);
+ if (has_vm && !x[ii].c_vm.empty()) c_vm[i] = std::string(x[ii].c_vm);
+ if (!x[ii].v.empty()) { // can only be utf8 if c_t = "str"
+ if (x[ii].c_t.empty() && x[ii].f_attr.empty())
+ v[i] = std::string(x[ii].v);
+ else
+ v[i] = Rcpp::String(x[ii].v);
+ }
+ if (!x[ii].f.empty()) f[i] = Rcpp::String(x[ii].f);
+ if (!x[ii].f_attr.empty()) f_attr[i] = std::string(x[ii].f_attr);
+ if (!x[ii].is.empty()) is[i] = Rcpp::String(x[ii].is);
+ }
+
+ // Assign and return a dataframe
+ if (has_cm && has_ph && has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_cm") = c_cm,
+ Rcpp::Named("c_ph") = c_ph,
+ Rcpp::Named("c_vm") = c_vm,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (has_cm && has_ph && !has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_cm") = c_cm,
+ Rcpp::Named("c_ph") = c_ph,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (has_cm && !has_ph && has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_cm") = c_cm,
+ Rcpp::Named("c_vm") = c_vm,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (!has_cm && has_ph && has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_ph") = c_ph,
+ Rcpp::Named("c_vm") = c_vm,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (has_cm && !has_ph && !has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_cm") = c_cm,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (!has_cm && has_ph && !has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_ph") = c_ph,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else if (!has_cm && !has_ph && has_vm) {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("c_vm") = c_vm,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ } else {
+ return Rcpp::wrap(
+ Rcpp::DataFrame::create(
+ Rcpp::Named("r") = r,
+ Rcpp::Named("row_r") = row_r,
+ Rcpp::Named("c_r") = c_r,
+ Rcpp::Named("c_s") = c_s,
+ Rcpp::Named("c_t") = c_t,
+ Rcpp::Named("v") = v,
+ Rcpp::Named("f") = f,
+ Rcpp::Named("f_attr") = f_attr,
+ Rcpp::Named("is") = is,
+ Rcpp::Named("stringsAsFactors") = false
+ )
+ );
+ }
+
+}
diff --git a/src/openxlsx2_types.h b/src/openxlsx2_types.h
index c914bc179..e2da5e991 100644
--- a/src/openxlsx2_types.h
+++ b/src/openxlsx2_types.h
@@ -57,69 +57,6 @@ enum celltype {
// Converts the imported values from c++ std::vector to an R dataframe.
// Whenever new fields are spotted they have to be added here
namespace Rcpp {
-template <>
-inline SEXP wrap(const std::vector& x) {
- R_xlen_t n = static_cast(x.size());
-
- // Vector structure identical to xml_col from openxlsx2_types.h
- Rcpp::CharacterVector r(no_init(n)); // cell name: A1, A2 ...
- Rcpp::CharacterVector row_r(no_init(n)); // row name: 1, 2, ..., 9999
-
- Rcpp::CharacterVector c_r(no_init(n)); // col name: A, B, ..., ZZ
- Rcpp::CharacterVector c_s(no_init(n)); // cell style
- Rcpp::CharacterVector c_t(no_init(n)); // cell type
- Rcpp::CharacterVector c_cm(no_init(n));
- Rcpp::CharacterVector c_ph(no_init(n));
- Rcpp::CharacterVector c_vm(no_init(n));
-
- Rcpp::CharacterVector v(no_init(n)); // tag
- Rcpp::CharacterVector f(no_init(n)); // tag
- Rcpp::CharacterVector f_attr(no_init(n)); // attributes
- Rcpp::CharacterVector is(no_init(n)); // tag
-
- // struct to vector
- // We have to convert utf8 inputs via Rcpp::String for non unicode R sessions
- // Ideally there would be a function that calls Rcpp::String only if needed
- for (R_xlen_t i = 0; i < n; ++i) {
- size_t ii = static_cast(i);
- if (!x[ii].r.empty()) r[i] = std::string(x[ii].r);
- if (!x[ii].row_r.empty()) row_r[i] = std::string(x[ii].row_r);
- if (!x[ii].c_r.empty()) c_r[i] = std::string(x[ii].c_r);
- if (!x[ii].c_s.empty()) c_s[i] = std::string(x[ii].c_s);
- if (!x[ii].c_t.empty()) c_t[i] = std::string(x[ii].c_t);
- if (!x[ii].c_cm.empty()) c_cm[i] = std::string(x[ii].c_cm);
- if (!x[ii].c_ph.empty()) c_ph[i] = Rcpp::String(x[ii].c_ph);
- if (!x[ii].c_vm.empty()) c_vm[i] = std::string(x[ii].c_vm);
- if (!x[ii].v.empty()) { // can only be utf8 if c_t = "str"
- if (x[ii].c_t.empty() && x[ii].f_attr.empty())
- v[i] = std::string(x[ii].v);
- else
- v[i] = Rcpp::String(x[ii].v);
- }
- if (!x[ii].f.empty()) f[i] = Rcpp::String(x[ii].f);
- if (!x[ii].f_attr.empty()) f_attr[i] = std::string(x[ii].f_attr);
- if (!x[ii].is.empty()) is[i] = Rcpp::String(x[ii].is);
- }
-
- // Assign and return a dataframe
- return Rcpp::wrap(
- Rcpp::DataFrame::create(
- Rcpp::Named("r") = r,
- Rcpp::Named("row_r") = row_r,
- Rcpp::Named("c_r") = c_r,
- Rcpp::Named("c_s") = c_s,
- Rcpp::Named("c_t") = c_t,
- Rcpp::Named("c_cm") = c_cm,
- Rcpp::Named("c_ph") = c_ph,
- Rcpp::Named("c_vm") = c_vm,
- Rcpp::Named("v") = v,
- Rcpp::Named("f") = f,
- Rcpp::Named("f_attr") = f_attr,
- Rcpp::Named("is") = is,
- Rcpp::Named("stringsAsFactors") = false
- )
- );
-}
template <>
inline SEXP wrap(const vec_string& x) {
diff --git a/src/write_file.cpp b/src/write_file.cpp
index cbb728b63..d715a29fd 100644
--- a/src/write_file.cpp
+++ b/src/write_file.cpp
@@ -40,6 +40,12 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc)
uint32_t pugi_parse_flags = pugi::parse_cdata | pugi::parse_wconv_attribute | pugi::parse_ws_pcdata | pugi::parse_eol;
// uint32_t pugi_format_flags = pugi::format_raw | pugi::format_no_escapes;
+ bool has_cm = cc.containsElementNamed("c_cm");
+ bool has_ph = cc.containsElementNamed("c_ph");
+ bool has_vm = cc.containsElementNamed("c_vm");
+
+ Rcpp::CharacterVector cc_c_cm, cc_c_ph, cc_c_vm;
+
// we cannot access rows directly in the dataframe.
// Have to extract the columns and use these
Rcpp::CharacterVector cc_row_r = cc["row_r"]; // 1
@@ -47,9 +53,9 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc)
Rcpp::CharacterVector cc_v = cc["v"]; // can be utf8
Rcpp::CharacterVector cc_c_t = cc["c_t"];
Rcpp::CharacterVector cc_c_s = cc["c_s"];
- Rcpp::CharacterVector cc_c_cm = cc["c_cm"];
- Rcpp::CharacterVector cc_c_ph = cc["c_ph"]; // can be utf8
- Rcpp::CharacterVector cc_c_vm = cc["c_vm"];
+ if (has_cm) cc_c_cm = cc["c_cm"];
+ if (has_ph) cc_c_ph = cc["c_ph"];
+ if (has_vm) cc_c_vm = cc["c_vm"];
Rcpp::CharacterVector cc_f = cc["f"]; // can be utf8
Rcpp::CharacterVector cc_f_attr = cc["f_attr"];
Rcpp::CharacterVector cc_is = cc["is"]; // can be utf8
@@ -87,16 +93,16 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc)
// update lastrow
lastrow = thisrow;
- if ( // skip blank cells entirely
- cc_c_s[i] == "" &&
- cc_c_t[i] == "" &&
- cc_c_cm[i] == "" &&
- cc_c_ph[i] == "" &&
- cc_c_vm[i] == "" &&
- cc_v[i] == "" &&
- cc_f[i] == "" &&
- cc_f_attr[i] == "" &&
- cc_is[i] == ""
+ if (
+ cc_c_s[i].empty() &&
+ cc_c_t[i].empty() &&
+ (!has_cm || (has_cm && cc_c_cm[i].empty())) &&
+ (!has_ph || (has_ph && cc_c_ph[i].empty())) &&
+ (!has_vm || (has_vm && cc_c_vm[i].empty())) &&
+ cc_v[i].empty() &&
+ cc_f[i].empty() &&
+ cc_f_attr[i].empty() &&
+ cc_is[i].empty()
) {
continue;
}
@@ -118,15 +124,15 @@ pugi::xml_document xml_sheet_data(Rcpp::DataFrame row_attr, Rcpp::DataFrame cc)
cell.append_attribute("t") = std::string(cc_c_t[i]).c_str();
// CellMetaIndex: suppress curly brackets in spreadsheet software
- if (!std::string(cc_c_cm[i]).empty())
+ if (has_cm && !std::string(cc_c_cm[i]).empty())
cell.append_attribute("cm") = std::string(cc_c_cm[i]).c_str();
// phonetics spelling
- if (!std::string(cc_c_ph[i]).empty())
- cell.append_attribute("ph") = to_string(cc_c_ph[i]).c_str();
+ if (has_ph && !std::string(cc_c_ph[i]).empty())
+ cell.append_attribute("ph") = std::string(cc_c_ph[i]).c_str();
// suppress curly brackets in spreadsheet software
- if (!std::string(cc_c_vm[i]).empty())
+ if (has_vm && !std::string(cc_c_vm[i]).empty())
cell.append_attribute("vm") = std::string(cc_c_vm[i]).c_str();
// append nodes ...
diff --git a/tests/testthat/test-date_time_conversion.R b/tests/testthat/test-date_time_conversion.R
index 67d20cffc..89cbfc01e 100644
--- a/tests/testthat/test-date_time_conversion.R
+++ b/tests/testthat/test-date_time_conversion.R
@@ -47,7 +47,7 @@ test_that("convert hms works", {
exp <- data.frame(
r = "A1", row_r = "1", c_r = "A", c_s = "1", c_t = "",
- c_cm = "", c_ph = "", c_vm = "", v = "0.509189814814815",
+ v = "0.509189814814815",
f = "", f_attr = "", is = "", typ = "15",
stringsAsFactors = FALSE)
got <- wb$worksheets[[1]]$sheet_data$cc
diff --git a/tests/testthat/test-formulas.R b/tests/testthat/test-formulas.R
index 44d279830..93d0aa4a6 100644
--- a/tests/testthat/test-formulas.R
+++ b/tests/testthat/test-formulas.R
@@ -39,7 +39,7 @@ test_that("writing formulas with cell metadata works", {
exp <- data.frame(
r = "A1", row_r = "1", c_r = "A", c_s = "", c_t = "",
- c_cm = "1", c_ph = "", c_vm = "", v = "", f = "SUM(ABS(A2:A11))",
+ c_cm = "1", v = "", f = "SUM(ABS(A2:A11))",
f_attr = "t=\"array\" ref=\"A1\"", is = "",
typ = "14",
stringsAsFactors = FALSE)
@@ -146,6 +146,7 @@ test_that("array formula detection works", {
})
test_that("writing shared formulas works", {
+ # somehow this test is failing in Rstudio and I do not know why
df <- data.frame(
x = 1:5,
y = 1:5 * 2,
diff --git a/tests/testthat/test-save.R b/tests/testthat/test-save.R
index d2fd742de..7b7f5ce69 100644
--- a/tests/testthat/test-save.R
+++ b/tests/testthat/test-save.R
@@ -263,9 +263,6 @@ test_that("write cells without data", {
c_r = c("B", "C", "B", "C"),
c_s = c("", "", "", ""),
c_t = c("", "", "", ""),
- c_cm = c("", "", "", ""),
- c_ph = c("", "", "", ""),
- c_vm = c("", "", "", ""),
v = c("", "", "", ""),
f = c("", "", "", ""),
f_attr = c("", "", "", ""),
diff --git a/tests/testthat/test-wb_functions.R b/tests/testthat/test-wb_functions.R
index f74d254de..f595769e8 100644
--- a/tests/testthat/test-wb_functions.R
+++ b/tests/testthat/test-wb_functions.R
@@ -543,7 +543,7 @@ test_that("creating a formula matrix works", {
shared = TRUE
)
- exp <- c(210, 13)
+ exp <- c(210, 10)
got <- dim(wb$worksheets[[1]]$sheet_data$cc)
expect_equal(exp, got)
@@ -564,7 +564,7 @@ test_that("writing formula dataframes works", {
dims = wb_dims(x = df, from_row = 13, col_names = FALSE)
)
- exp <- c(210, 13)
+ exp <- c(210, 10)
got <- dim(wb$worksheets[[1]]$sheet_data$cc)
expect_equal(exp, got)
diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R
index 448fce88c..6f9b1a354 100644
--- a/tests/testthat/test-write.R
+++ b/tests/testthat/test-write.R
@@ -6,8 +6,7 @@ test_that("write_formula", {
# array formula for a single cell
exp <- structure(
list(r = "E2", row_r = "2", c_r = "E", c_s = "",
- c_t = "", c_cm = "",
- c_ph = "", c_vm = "",
+ c_t = "",
v = "", f = "SUM(C2:C11*D2:D11)",
f_attr = "t=\"array\" ref=\"E2\"",
is = "", typ = "11"),
@@ -23,7 +22,7 @@ test_that("write_formula", {
cc <- wb$worksheets[[1]]$sheet_data$cc
got <- cc[cc$row_r == "2" & cc$c_r == "E", ]
- expect_equal(exp[1:13], got[1:13])
+ expect_equal(exp[1:10], got[1:10])
rownames(exp) <- 1L
@@ -37,7 +36,7 @@ test_that("write_formula", {
cc <- wb$worksheets[[1]]$sheet_data$cc
got <- cc[cc$row_r == "2" & cc$c_r == "E", ]
- expect_equal(exp[1:11], got[1:11])
+ expect_equal(exp[1:10], got[1:10])
})
@@ -226,9 +225,6 @@ test_that("update cell(s)", {
c_r = c("B", "C", "D", "E", "F", "G"),
c_s = c("1", "1", "1", "1", "1", "1"),
c_t = c("", "", "", "", "", ""),
- c_cm = c("", "", "", "", "", ""),
- c_ph = c("", "", "", "", "", ""),
- c_vm = c("", "", "", "", "", ""),
v = c("", "", "", "", "", ""),
f = c("", "", "", "", "", ""),
f_attr = c("", "", "", "", "", ""),