Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp11 stop in constructor DO NOT MERGE #690

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/XlsCellSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cpp11/integers.hpp"
#include "cpp11/list.hpp"
#include "cpp11/protect.hpp"
#include "cpp11/R.hpp"
#include "cpp11/sexp.hpp"
#include "cpp11/strings.hpp"

Expand Down Expand Up @@ -43,7 +44,8 @@ class XlsCellSet {
spinner_.spin();
pWB_ = xls_open_file(wb.path().c_str(), "UTF-8", &error);
if (!pWB_) {
cpp11::stop(
Rf_errorcall(
R_NilValue,
"\n filepath: %s\n libxls error: %s",
wb.path().c_str(),
xls::xls_getError(error)
Expand All @@ -56,7 +58,16 @@ class XlsCellSet {
cpp11::stop("Sheet '%s' (position %d): cannot be opened",
sheetName_.c_str(), sheet_i + 1);
}
xls_parseWorkSheet(pWS_);
error = xls::xls_parseWorkSheet(pWS_);
if (error != xls::LIBXLS_OK) {
Rf_errorcall(
R_NilValue,
"\n filepath: %s\n sheet: %s\n libxls error: %s",
wb.path().c_str(),
sheetName_.c_str(),
xls::xls_getError(error)
);
}
spinner_.spin();

// shim = TRUE when user specifies geometry via `range`
Expand Down
12 changes: 6 additions & 6 deletions src/XlsWorkBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include "libxls/xls.h"
#include "libxls/xlsstruct.h"

#include "cpp11/R.hpp"
#include "cpp11/r_string.hpp"
#include "cpp11/strings.hpp"

#include <sstream>

class XlsWorkBook {

// common to Xls[x]WorkBook
Expand Down Expand Up @@ -37,10 +36,11 @@ class XlsWorkBook {
xls::xls_error_t error = xls::LIBXLS_OK;
xls::xlsWorkBook* pWB_ = xls::xls_open_file(path_.c_str(), "UTF-8", &error);
if (!pWB_) {
auto err = xls::xls_getError(error);
std::stringstream ss;
ss << "\n filepath: " << path_ << "\n libxls error: " << err;
throw std::runtime_error(ss.str());
cpp11::stop(
"\n filepath: %s\n libxls error: %s",
path_.c_str(),
xls::xls_getError(error)
);
}

n_sheets_ = pWB_->sheets.count;
Expand Down