Skip to content

Commit 421e471

Browse files
+macro R_ERROR_NOT_OK similar to RETURN_NOT_OK but that Rcpp::stop()s
1 parent f5e3eff commit 421e471

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

r/src/arrow_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <arrow/api.h>
2424
#include <arrow/type.h>
2525

26+
#define R_ERROR_NOT_OK(s) do { if(!s.ok()) Rcpp::stop(s.ToString()); } while (0);
27+
2628
template <typename T>
2729
class static_ptr {
2830
public:

r/src/buffer.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,16 @@ std::shared_ptr<arrow::Schema> Table_schema(const std::shared_ptr<arrow::Table>&
141141
// [[Rcpp::export]]
142142
int RecordBatch_to_file(const std::shared_ptr<arrow::RecordBatch>& batch, std::string path) {
143143
std::shared_ptr<arrow::io::OutputStream> stream;
144-
auto s = arrow::io::FileOutputStream::Open(path, &stream);
145-
146144
std::shared_ptr<arrow::ipc::RecordBatchWriter> file_writer;
147-
s = arrow::ipc::RecordBatchFileWriter::Open(stream.get(), batch->schema(), &file_writer);
148-
s = file_writer->WriteRecordBatch(*batch, true);
149-
s = file_writer->Close();
145+
146+
R_ERROR_NOT_OK(arrow::io::FileOutputStream::Open(path, &stream));
147+
R_ERROR_NOT_OK(arrow::ipc::RecordBatchFileWriter::Open(stream.get(), batch->schema(), &file_writer));
148+
R_ERROR_NOT_OK(file_writer->WriteRecordBatch(*batch, true));
149+
R_ERROR_NOT_OK(file_writer->Close());
150+
150151
int64_t offset;
151-
s = stream->Tell(&offset);
152-
s = stream->Close();
152+
R_ERROR_NOT_OK(stream->Tell(&offset));
153+
R_ERROR_NOT_OK(stream->Close());
153154
return offset;
154155
}
155156

156-
157-
158-

0 commit comments

Comments
 (0)