romainfrancois commented on pull request #7660:
URL: https://github.com/apache/arrow/pull/7660#issuecomment-655574225


   Some more progress today. 
   
   ``` r
   library(arrow, warn.conflicts = FALSE)
   
   # with explicit type=
   #   no deduction, but testing
   raws <- vctrs::list_of(as.raw(1:4), as.raw(1:4))
   a1 <- Array$create(raws, type = binary())
   a2 <- Array$create(raws, type = large_binary())
   a3 <- Array$create(raws, type = fixed_size_binary(4L))
   a1$as_vector()
   #> <binary[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   a2$as_vector()
   #> <large_binary[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   a3$as_vector()
   #> <fixed_size_binary<4>[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   
   # with type deduced from class, we should have functions for this. 
   
   a1 <- Array$create(
     vctrs::new_list_of(list(as.raw(1:4), as.raw(1:4)), class = "arrow_binary")
   )
   a2 <- Array$create(
     vctrs::new_list_of(list(as.raw(1:4), as.raw(1:4)), class = 
"arrow_large_binary")
   )
   a3 <- Array$create(
     vctrs::new_list_of(list(as.raw(1:4), as.raw(1:4)), class = 
"arrow_fixed_size_binary", byte_width = 4L)
   )
   a1$as_vector()
   #> <binary[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   a2$as_vector()
   #> <large_binary[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   a3$as_vector()
   #> <fixed_size_binary<4>[2]>
   #> [[1]]
   #> [1] 01 02 03 04
   #> 
   #> [[2]]
   #> [1] 01 02 03 04
   ```
   
   <sup>Created on 2020-07-08 by the [reprex 
package](https://reprex.tidyverse.org) (v0.3.0.9001)</sup>
   
   Will tackle FixedSizeList on the same model. 
   
   Now that we have the R classes `arrow_binary`, `arrow_large_binary`, and 
`arrow_fixed_size_binary`, perhaps we don't really need to inherit from 
`vctrs_list_of`, I actually had to backpedal it with some methods to make it 
look sort of ok: 
   
   ```r
   # vctrs support -----------------------------------------------------------
   
   #' @importFrom vctrs vec_ptype_full vec_ptype_abbr obj_str_footer
   #' @method vec_ptype_full arrow_fixed_size_binary
   #' @export
   vec_ptype_full.arrow_fixed_size_binary <- function(x, ...) {
     paste0("fixed_size_binary<", attr(x, "byte_width"), ">")
   }
   
   #' @method vec_ptype_full arrow_binary
   #' @export
   vec_ptype_full.arrow_binary <- function(x, ...) {
     "binary"
   }
   
   #' @method vec_ptype_full arrow_large_binary
   #' @export
   vec_ptype_full.arrow_large_binary <- function(x, ...) {
     "large_binary"
   }
   
   
   #' @method vec_ptype_abbr arrow_fixed_size_binary
   #' @export
   vec_ptype_abbr.arrow_fixed_size_binary <- 
vec_ptype_full.arrow_fixed_size_binary
   
   #' @method vec_ptype_abbr arrow_binary
   #' @export
   vec_ptype_abbr.arrow_binary <- vec_ptype_full.arrow_binary
   
   #' @method vec_ptype_abbr arrow_large_binary
   #' @export
   vec_ptype_abbr.arrow_large_binary <- vec_ptype_full.arrow_large_binary
   
   
   
   #' @method obj_str_footer arrow_fixed_size_binary
   #' @export
   obj_str_footer.arrow_fixed_size_binary <- function(x, ..., indent.str = "", 
nest.lev = 0) {
     invisible(NULL)
   }
   
   #' @method obj_str_footer arrow_binary
   #' @export
   obj_str_footer.arrow_binary <- obj_str_footer.arrow_fixed_size_binary
   
   #' @method obj_str_footer arrow_large_binary
   #' @export
   obj_str_footer.arrow_large_binary <- obj_str_footer.arrow_fixed_size_binary
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to