Split file every nlines

Get files from splitting.

split_file(file, every_nlines, prefix_out = tempfile(),
  repeat_header = FALSE)

get_split_files(split_file_out)

Arguments

file

Path to file that you want to split.

every_nlines

Maximum number of lines in new file parts.

prefix_out

Prefix for created files. Default uses tempfile().

repeat_header

Whether to repeat the header row in each file. Default is FALSE.

split_file_out

Output of split_file.

Value

A list with

  • name_in: input parameter file,

  • prefix_out: input parameter `prefix_out``,

  • nfiles: Number of files (parts) created,

  • nlines_part: input parameter every_nlines,

  • nlines_all: total number of lines of file.

Vector of file paths created by split_file.

Examples

tmp <- fwrite2(iris)
infos <- split_file(tmp, 100)
str(infos)
#> List of 6
#>  $ name_in      : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpq2HStE\\file40f821d7102d"
#>  $ prefix_out   : chr "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpq2HStE\\file40f855f46bc3"
#>  $ nfiles       : int 2
#>  $ nlines_part  : int 100
#>  $ nlines_all   : num 151
#>  $ repeat_header: logi FALSE
get_split_files(infos)
#> [1] "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpq2HStE\\file40f855f46bc3_1.txt"
#> [2] "C:\\Users\\au639593\\AppData\\Local\\Temp\\Rtmpq2HStE\\file40f855f46bc3_2.txt"