Skip to content

Commit

Permalink
schema_col_classes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed May 22, 2024
1 parent 63804fe commit c92b3be
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data_prep/R/schema_col_classes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://stackoverflow.com/questions/77557377/how-to-convert-int-to-double-when-using-arrow-to-read-in-multiple-csvs-with-open

library(data.table)


df <- fread('./read_guides/readguide_2010_population.csv')


df[, col_class := fcase(decimal_places>0, '= numeric(),',
between(length, 1, 2) & is.na(decimal_places), '= integer8(),',
between(length, 3, 4) & is.na(decimal_places), '= integer16(),',
between(length, 5, 9) & is.na(decimal_places), '= integer32(),',
length > 9 & is.na(decimal_places), '= integer64(),',
default= '= string(),'
)]


df[,. (var_name, col_class)] |> print()

0 comments on commit c92b3be

Please sign in to comment.