ropensci/readODS

Experiment with a for loop with less comparisons

chainsawriot opened this issue · 0 comments

readODS/R/writeODS.R

Lines 103 to 116 in 3833747

for (j in colj) {
value <- as.character(x[i, j, drop = TRUE])
write_empty_cell <- FALSE
if (is.na(value) && !na_as_string) {
write_empty_cell <- TRUE
}
if (is.na(value) && na_as_string) {
type <- "string"
value <- "NA"
} else {
type <- types[j]
}
.cell_out(type = type, value = value, con = con, write_empty_cell = write_empty_cell)
}

Most of the cells should not be NA

        for (j in colj) {
            value <- as.character(x[i, j, drop = TRUE])
            type <- types[j]
            if (!is.na(value)) {
                .cell_out(type = type, value = value, con = con, write_empty_cell = FALSE)
                next
            }
            ## now, it's NA
            if (!na_as_string) {
                .cell_out(type = type, value = value, con = con, write_empty_cell = TRUE)
                next
            }
            ## na_as_string
            .cell_out(type = "string", value = value, con = con, write_empty_cell = FALSE)
        }