Skip to content

Commit

Permalink
Allow pl$List() and pl$Struct() (#398)
Browse files Browse the repository at this point in the history
Co-authored-by: Etienne Bacher <[email protected]>
  • Loading branch information
sorhawell and etiennebacher authored Sep 26, 2023
1 parent 44cbe9b commit 0bf921e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
22 changes: 18 additions & 4 deletions R/datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ DataType_constructors = list(
},

# doc below pl_List
List = function(datatype) {
List = function(datatype = "unknown") {
if (is.character(datatype) && length(datatype) == 1) {
datatype = .pr$DataType$new(datatype)
}
Expand All @@ -185,7 +185,7 @@ DataType_constructors = list(
Struct = function(...) {
result({
largs = list2(...)
if (is.list(largs[[1]])) {
if (length(largs) >= 1 && is.list(largs[[1]])) {
largs = largs[[1]]
element_name = "list element"
} else {
Expand Down Expand Up @@ -239,13 +239,27 @@ NULL
#'
#' # Find any DataType via pl$dtypes
#' print(pl$dtypes)
#'
#' # check if an element is any kind of Struct()
#' test = pl$Struct(pl$UInt64)
#' pl$same_outer_dt(test, pl$Struct())
#'
#' # `test` is a type of Struct, but it doesn't mean it is equal to an empty Struct
#' test == pl$Struct()
NULL

#' Create List DataType
#' @keywords pl
#' @name pl_List
#' @param datatype an inner DataType
#' @param datatype an inner DataType, default is "Unknown" (placeholder for when inner DataType
#' does not matter, e.g. as used in example)
#' @return a list DataType with an inner DataType
#' @format function
#' @examples pl$List(pl$List(pl$Boolean))
#' @examples
#' # some nested List
#' pl$List(pl$List(pl$Boolean))
#'
#' # check if some maybe_list is a List DataType
#' maybe_List = pl$List(pl$UInt64)
#' pl$same_outer_dt(maybe_List, pl$List())
NULL
8 changes: 7 additions & 1 deletion man/pl_List.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/pl_Struct_datatype.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bf921e

Please sign in to comment.