-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor xlsx col type and col name handling (#261)
* add new param n for guessing col_type * Remove all column name processing from colTypes() * Move colName and colType comparison out of readCols() * Stop dropping blank columns; fixes #157 * Move tests into more logical places * More specific error when col_names or col_types has wrong length * Rcpp churn * If no data, call it blank right here * Simplify col_type learning loop * Sketch my grand plans * Check and test col_types * Simplify readCols() loop * Recycle col_types if length 1; fixes #127 * Deprecate `col_types = "blank"`; fixes #260 * Rationalize joint processing of col_names + col_types; fixes #81 * Ignore docs for xls format * Fix/update xlsx_col_types() Even though I'm not sure what it's for. * Delete benchmarks.cpp, home of the shifty, vestigial parseXml()and countRows() * Add bullets to NEWS * README and pkgdown * Groom error messages and tests thereof * Wording in NEWS * Stop for unknown type * Move CELL_SKIP; add comment re: enum order * Recycle length-one col_type with std::fill() * Indenting * Helper function for reconciling col names * Helper function for recycling col types * Simplify col_type learning loop; avoid cell copy * Simplify and avoid cell copy in readCols() too * It's guess_max, not max_guess * Delete comment, test code style * Cleaner with i, j
- Loading branch information
Showing
25 changed files
with
423 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
^_pkgdown\.yml$ | ||
^docs$ | ||
^clippy$ | ||
^\[MS-XLS\]\.pdf$ | ||
^excelfileformat\.pdf$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
.RData | ||
~* | ||
clippy | ||
\[MS-XLS\].pdf | ||
excelfileformat.pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef READXL_COLSPEC_ | ||
#define READXL_COLSPEC_ | ||
|
||
#include <Rcpp.h> | ||
#include "CellType.h" | ||
|
||
inline std::vector<CellType> recycleTypes(std::vector<CellType> types, | ||
int ncol) { | ||
if (types.size() == 1) { | ||
types.resize(ncol); | ||
std::fill(types.begin(), types.end(), types[0]); | ||
} | ||
return types; | ||
} | ||
|
||
inline Rcpp::CharacterVector reconcileNames(Rcpp::CharacterVector names, | ||
const std::vector<CellType>& types, | ||
int sheet) { | ||
size_t ncol_names = names.size(); | ||
size_t ncol_types = types.size(); | ||
|
||
if (ncol_names == ncol_types) { | ||
return names; | ||
} | ||
|
||
size_t ncol_noskip = 0; | ||
for (size_t i = 0; i < types.size(); i++) { | ||
if (types[i] != CELL_SKIP) { | ||
ncol_noskip++; | ||
} | ||
} | ||
if (ncol_names != ncol_noskip) { | ||
Rcpp::stop("Sheet %d has %d columns (%d unskipped), but `col_names` has length %d.", | ||
sheet + 1, ncol_types, ncol_noskip, ncol_names); | ||
} | ||
|
||
Rcpp::CharacterVector newNames(ncol_types, ""); | ||
size_t j_short = 0; | ||
for (size_t j_long = 0; j_long < ncol_types; ++j_long) { | ||
if (types[j_long] == CELL_SKIP) { | ||
continue; | ||
} | ||
newNames[j_long] = names[j_short]; | ||
j_short++; | ||
} | ||
return newNames; | ||
} | ||
|
||
#endif |
Oops, something went wrong.