@@ -7,8 +7,14 @@ read_arrow_schema <- function(file) {
77 }
88}
99
10- apply_arrow_schema <- function (tab , file , arrow_schema , dicts , types ,
11- col_select ) {
10+ apply_arrow_schema <- function (
11+ tab ,
12+ file ,
13+ arrow_schema ,
14+ dicts ,
15+ types ,
16+ col_select
17+ ) {
1218 if (is.na(arrow_schema )) {
1319 return (tab )
1420 }
@@ -19,7 +25,9 @@ apply_arrow_schema <- function(tab, file, arrow_schema, dicts, types,
1925 }
2026 for (idx in spec $ difftime ) {
2127 # only if INT64, otherwise hms, probably
22- if (types [[idx ]] != 2 ) next
28+ if (types [[idx ]] != 2 ) {
29+ next
30+ }
2331 mult <- switch (
2432 spec $ columns $ type [[idx ]]$ unit ,
2533 SECOND = 1 ,
@@ -37,10 +45,13 @@ arrow_find_special <- function(asch, file, col_select = NULL) {
3745 amd <- tryCatch(
3846 parse_arrow_schema(asch )$ columns ,
3947 error = function (e ) {
40- warning(sprintf(
41- " Failed to parse Arrow schema from parquet file at '%s'" ,
42- file
43- ), call. = TRUE )
48+ warning(
49+ sprintf(
50+ " Failed to parse Arrow schema from parquet file at '%s'" ,
51+ file
52+ ),
53+ call. = TRUE
54+ )
4455 NULL
4556 }
4657 )
@@ -98,7 +109,6 @@ float_precision_names <- c(
98109date_unit_names <- c(
99110 DAY = 0L ,
100111 MILLISECOND = 1L
101-
102112)
103113
104114time_unit_names <- c(
@@ -174,8 +184,12 @@ encode_arrow_schema_r <- function(df, schema) {
174184 dates <- vapply(df , function (c ) inherits(c , " Date" ), logical (1 ))
175185 hmss <- vapply(df , function (c ) inherits(c , " hms" ), logical (1 ))
176186 psxcts <- vapply(df , function (c ) inherits(c , " POSIXct" ), logical (1 ))
177- fctrs <- vapply(df , function (c ) inherits(c , " factor" ), logical (1 ))
178- dfts <- vapply(df , function (c ) ! inherits(c , " hms" ) && inherits(c , " difftime" ), logical (1 ))
187+ fctrs <- vapply(df , function (c ) inherits(c , " factor" ), logical (1 ))
188+ dfts <- vapply(
189+ df ,
190+ function (c ) ! inherits(c , " hms" ) && inherits(c , " difftime" ),
191+ logical (1 )
192+ )
179193 typemap <- c(
180194 " integer" = " Int" ,
181195 " double" = " FloatingPoint" ,
@@ -233,7 +247,8 @@ encode_arrow_schema_r <- function(df, schema) {
233247
234248# Replace strings with numeric IDs, so we can use them in C++
235249fill_arrow_schema_enums_type <- function (type_type , type ) {
236- switch (type_type ,
250+ switch (
251+ type_type ,
237252 " FloatingPoint" = {
238253 type $ precision <- float_precision_names [type $ precision ]
239254 },
@@ -260,7 +275,7 @@ fill_arrow_schema_enums_type <- function(type_type, type) {
260275
261276fill_arrow_schema_enums_dict <- function (dict ) {
262277 if (! is.null(dict )) {
263- dict $ dictionary_kind <- dict_kind_names [dict $ dictionary_kind ]
278+ dict $ dictionary_kind <- dict_kind_names [dict $ dictionary_kind ]
264279 }
265280 dict
266281}
@@ -283,7 +298,7 @@ fill_arrow_schema_enums <- function(schema) {
283298 schema
284299}
285300
286- encode_arrow_schema <- function (df ) {
301+ encode_arrow_schema <- function (df ) {
287302 schema <- encode_arrow_schema_r(df )
288303 schema <- fill_arrow_schema_enums(schema )
289304 rawenc <- .Call(nanoparquet_encode_arrow_schema , schema )
@@ -295,11 +310,11 @@ encode_arrow_schema<- function(df) {
295310# Arrow only supports 8, 16, 32 and 64.
296311factor_bits <- function (x ) {
297312 l <- length(levels(x ))
298- if (l < 2 ^ (8 - 1 )) {
313+ if (l < 2 ^ (8 - 1 )) {
299314 8L
300- } else if (l < 2 ^ (16 - 1 )) {
315+ } else if (l < 2 ^ (16 - 1 )) {
301316 16L
302- } else if (l < 2 ^ (32 - 1 )) {
317+ } else if (l < 2 ^ (32 - 1 )) {
303318 32L
304319 } else {
305320 64L
0 commit comments