Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 22, 2023
1 parent 5e0cc04 commit d49b601
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions R/wb_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -1370,32 +1370,32 @@ wb_load <- function(
xti$lastSheet <- as.integer(xti$lastSheet) + 1L

sheets <- wb$get_sheet_names(escape = TRUE)
if (any(sel <- grepl("\\s", sheets)))
sheets[sel] <- shQuote(sheets[sel], type = "sh")

xti$sheets <- NA_character_ #(otherwise in missing cases: all is <NA>)
# all id == 0 are local references, otherwise external references
# external references are written as "[0]sheetname!A1". Require
# handling of externalReferences.bin
sel <- !grepl("^rId", xti$type) & xti$firstSheet >= 0 #& xti$firstSheet == xti$lastSheet
sel <- !grepl("^rId", xti$type) & xti$firstSheet >= 0

if (any(sel)) {

# if (xti$firstSheet[sel] == xti$firstSheet[sel]) {
# TODO add firstSheet != lastSheet
xti$sheets[sel] <- vapply(
xti$firstSheet[sel],
function(x) sheets[x],
FUN.VALUE = ""
)
# } else {
# xti$sheets[sel] <- vapply(
# xti$firstSheet[sel],
# function(x) sheets[x],
# FUN.VALUE = ""
# )
# }
for (i in seq_len(nrow(xti[sel, ]))) {
want <- xti$firstSheet[sel][i]

sheetName <- sheets[[want]]
if (xti$firstSheet[sel][i] < xti$lastSheet[sel][i]) {
want <- xti$lastSheet[sel][i]
sheetName <- paste0(sheetName, ":", sheets[[want]])
}

# should be a single reference now
val <- sheetName

if (grepl("[^A-Za-z0-9]", val))
val <- shQuote(val, type = "sh")

if (length(val)) xti$sheets[sel][i] <- val
}
}

### for external references we need to get the required sheet names first
Expand All @@ -1410,7 +1410,7 @@ wb_load <- function(

# TODO: How are references to the same external link,
# but different sheet handled?
sel <- grepl("^rId", xti$type) & xti$firstSheet >= 0 # & xti$firstSheet == xti$lastSheet
sel <- grepl("^rId", xti$type) & xti$firstSheet >= 0

if (any(sel)) {

Expand All @@ -1432,8 +1432,8 @@ wb_load <- function(
val <- sprintf("[%s]%s", xti$ext_id[sel][i], sheetName)

# non ascii or whitespace
if (any(sel2 <- grepl("[^A-Za-z0-9]", val)))
val[sel2] <- shQuote(val[sel2], type = "sh")
if (grepl("[^A-Za-z0-9]", val))
val <- shQuote(val, type = "sh")

if (length(val)) xti$sheets[sel][i] <- val
}
Expand Down
4 changes: 2 additions & 2 deletions src/xlsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ int workbook_bin(std::string filePath, std::string outPath, bool debug) {

if (fields->fBuiltin) {
// add the builtin xl name namespace
if (name.find("_xlnm.") == -1)
if (name.find("_xlnm.") == std::string::npos)
name = "_xlnm." + name;
}

Expand Down Expand Up @@ -1711,7 +1711,7 @@ int workbook_bin(std::string filePath, std::string outPath, bool debug) {
// Rcpp::Rcout << "reference_type: " << cXti << std::endl;
for (uint32_t i = 0; i < cXti; ++i) {
std::vector<int> xti = Xti(bin, swapit);
if (xti[0] > reference_type.size()) Rcpp::stop("references do not match");
if ((size_t)xti[0] > reference_type.size()) Rcpp::stop("references do not match");
std::string tmp = "<xti id=\"" + std::to_string(xti[0]) +
"\" firstSheet=\"" + std::to_string(xti[1]) +
"\" lastSheet=\"" + std::to_string(xti[2]) +
Expand Down

0 comments on commit d49b601

Please sign in to comment.