Skip to content

Commit

Permalink
more generic print method
Browse files Browse the repository at this point in the history
  • Loading branch information
romainfrancois committed Sep 24, 2018
1 parent 8d8cdd1 commit 767e9d9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 88 deletions.
3 changes: 2 additions & 1 deletion r/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Imports:
R6,
vctrs,
fs,
tibble
tibble,
crayon
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.0.1.9000
Suggests:
Expand Down
37 changes: 13 additions & 24 deletions r/R/R6.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
`.:xp:.` = NULL,
set_pointer = function(xp){
self$`.:xp:.` <- xp
},
print = function(...){
cat(crayon::silver(glue::glue("{cl} <{p}>", cl = class(self)[[1]], p = self$pointer_address())), "\n")
if(!is.null(self$ToString)){
cat(self$ToString(), "\n")
}
invisible(self)
},
pointer_address = function(){
Object_pointer_address(self$pointer())
}
)
)
Expand All @@ -41,9 +51,6 @@
ToString = function() {
DataType_ToString(self)
},
print = function(...) {
cat( glue( "DataType({s})", s = DataType_ToString(self) ))
},
name = function() {
DataType_name(self)
},
Expand Down Expand Up @@ -385,9 +392,6 @@ decimal <- function(precision, scale) `arrow::Decimal128Type`$new(Decimal128Type
nullable = function() {
Field_nullable(self)
},
print = function(...) {
cat( glue( "Field<{s}>", s = Field_ToString(self)))
},
Equals = function(other) {
inherits(other, "arrow::Field") && Field_Equals(self, other)
}
Expand Down Expand Up @@ -418,21 +422,11 @@ field <- function(name, type) {
`arrow::NestedType` <- R6Class("arrow::NestedType", inherit = `arrow::DataType`)

`arrow::StructType` <- R6Class("arrow::StructType",
inherit = `arrow::NestedType`,
public = list(
print = function(...) {
cat( glue( "StructType({s})", s = DataType_ToString(self)))
}
)
inherit = `arrow::NestedType`
)

`arrow::Schema` <- R6Class("arrow::Schema",
inherit = `arrow::Object`,
public = list(
print = function(...) {
cat( glue( "{s}", s = Schema_ToString(self)))
}
)
inherit = `arrow::Object`
)

#' @rdname DataType
Expand All @@ -450,12 +444,7 @@ schema <- function(...){
#--------- list

`arrow::ListType` <- R6Class("arrow::ListType",
inherit = `arrow::NestedType`,
public = list(
print = function(...) {
cat( glue( "ListType({s})", s = ListType_ToString(self)))
}
)
inherit = `arrow::NestedType`
)

#' @rdname DataType
Expand Down
8 changes: 4 additions & 4 deletions r/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ Field_nullable <- function(type) {
.Call(`_arrow_Field_nullable`, type)
}

ping_arrow <- function() {
.Call(`_arrow_ping_arrow`)
}

MemoryPool_default <- function() {
.Call(`_arrow_MemoryPool_default`)
}
Expand Down Expand Up @@ -309,6 +305,10 @@ TimestampType_unit <- function(type) {
.Call(`_arrow_TimestampType_unit`, type)
}

Object_pointer_address <- function(obj) {
.Call(`_arrow_Object_pointer_address`, obj)
}

Status_ToString <- function(status) {
.Call(`_arrow_Status_ToString`, status)
}
Expand Down
23 changes: 12 additions & 11 deletions r/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,6 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// ping_arrow
std::string ping_arrow();
RcppExport SEXP _arrow_ping_arrow() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(ping_arrow());
return rcpp_result_gen;
END_RCPP
}
// MemoryPool_default
static_ptr<arrow::MemoryPool> MemoryPool_default();
RcppExport SEXP _arrow_MemoryPool_default() {
Expand Down Expand Up @@ -846,6 +836,17 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// Object_pointer_address
std::string Object_pointer_address(SEXP obj);
RcppExport SEXP _arrow_Object_pointer_address(SEXP objSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< SEXP >::type obj(objSEXP);
rcpp_result_gen = Rcpp::wrap(Object_pointer_address(obj));
return rcpp_result_gen;
END_RCPP
}
// Status_ToString
std::string Status_ToString(const std::shared_ptr<arrow::Status>& status);
RcppExport SEXP _arrow_Status_ToString(SEXP statusSEXP) {
Expand Down Expand Up @@ -925,7 +926,6 @@ static const R_CallMethodDef CallEntries[] = {
{"_arrow_Field_ToString", (DL_FUNC) &_arrow_Field_ToString, 1},
{"_arrow_Field_name", (DL_FUNC) &_arrow_Field_name, 1},
{"_arrow_Field_nullable", (DL_FUNC) &_arrow_Field_nullable, 1},
{"_arrow_ping_arrow", (DL_FUNC) &_arrow_ping_arrow, 0},
{"_arrow_MemoryPool_default", (DL_FUNC) &_arrow_MemoryPool_default, 0},
{"_arrow_MemoryPool_bytes_allocated", (DL_FUNC) &_arrow_MemoryPool_bytes_allocated, 1},
{"_arrow_MemoryPool_max_memory", (DL_FUNC) &_arrow_MemoryPool_max_memory, 1},
Expand Down Expand Up @@ -969,6 +969,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_arrow_DecimalType_scale", (DL_FUNC) &_arrow_DecimalType_scale, 1},
{"_arrow_TimestampType_timezone", (DL_FUNC) &_arrow_TimestampType_timezone, 1},
{"_arrow_TimestampType_unit", (DL_FUNC) &_arrow_TimestampType_unit, 1},
{"_arrow_Object_pointer_address", (DL_FUNC) &_arrow_Object_pointer_address, 1},
{"_arrow_Status_ToString", (DL_FUNC) &_arrow_Status_ToString, 1},
{"_arrow_Status_CodeAsString", (DL_FUNC) &_arrow_Status_CodeAsString, 1},
{"_arrow_Status_code", (DL_FUNC) &_arrow_Status_code, 1},
Expand Down
26 changes: 0 additions & 26 deletions r/src/hello.cpp

This file was deleted.

5 changes: 5 additions & 0 deletions r/src/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,8 @@ std::string TimestampType_timezone(const std::shared_ptr<arrow::TimestampType>&
arrow::TimeUnit::type TimestampType_unit(const std::shared_ptr<arrow::TimestampType>& type) {
return type->unit();
}

// [[Rcpp::export]]
std::string Object_pointer_address(SEXP obj){
return tfm::format("%p", EXTPTR_PTR(obj));
}
22 changes: 0 additions & 22 deletions r/src/r_arrow_types.h

This file was deleted.

0 comments on commit 767e9d9

Please sign in to comment.