# example with a dataframe
# we create the function to loop over the data.frame
read_method <- function(input, skip = 0L, n_max = Inf) {
# if we are after the end of the input we return an empty data.frame
if (skip+1 > nrow(input)) { return(data.frame()) }
# return the n_max row from skip + 1
input[(skip+1):(min(skip+n_max, nrow(input))),]
}
# we use it
write_parquet_by_chunk(
read_method = read_method,
input = mtcars,
path_to_parquet = tempfile(),
max_rows = 10,
)
#
# Example with haven::read_sas
#
# we need to pass two argument beside the 3 input, skip and n_max.
# We will use a closure :
my_read_closure <- function(encoding, columns) {
function(input, skip = OL, n_max = Inf) {
haven::read_sas(data_file = input,
n_max = n_max,
skip = skip,
encoding = encoding,
col_select = all_of(columns))
}
}
# we initialize the closure
read_method <- my_read_closure(encoding = "WINDOWS-1252", columns = c("Species", "Petal_Width"))
# we use it
write_parquet_by_chunk(
read_method = read_method,
input = system.file("examples","iris.sas7bdat", package = "haven"),
path_to_parquet = tempfile(),
max_rows = 75,
)
Run the code above in your browser using DataLab