1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
20 #' @title class DictionaryType
30 #' @rdname DictionaryType
31 #' @name DictionaryType
32 DictionaryType <- R6Class("DictionaryType",
33 inherit = FixedWidthType,
35 ToString = function() {
36 prettier_dictionary_type(DataType__ToString(self))
40 index_type = function() DictionaryType__index_type(self),
41 value_type = function() DictionaryType__value_type(self),
42 name = function() DictionaryType__name(self),
43 ordered = function() DictionaryType__ordered(self)
46 DictionaryType$create <- function(index_type = int32(),
49 assert_is(index_type, "DataType")
50 assert_is(value_type, "DataType")
51 DictionaryType__initialize(index_type, value_type, ordered)
54 #' Create a dictionary type
56 #' @param index_type A DataType for the indices (default [int32()])
57 #' @param value_type A DataType for the values (default [utf8()])
58 #' @param ordered Is this an ordered dictionary (default `FALSE`)?
60 #' @return A [DictionaryType]
61 #' @seealso [Other Arrow data types][data-type]
63 dictionary <- DictionaryType$create
65 prettier_dictionary_type <- function(x) {
66 # Prettier format the "ordered" attribute
67 x <- sub(", ordered=0", "", x)
68 sub("ordered=1", "ordered", x)