whitespace delimiter in vroom

Is it possible to use whitespace of any length as the column delimiter in vroom, as in sep="" for read.table.

For example, this works because the whitespace is one character:

library(vroom)
vroom("a b c\n1.0 2.0 3.0\n", delim = " ")
#> Observations: 1
#> Variables: 3
#> dbl [3]: a, b, c
#> 
#> Call `spec()` for a copy-pastable column specification
#> Specify the column types with `col_types` to quiet this message
#> # A tibble: 1 x 3
#>       a     b     c
#>   <dbl> <dbl> <dbl>
#> 1     1     2     3

But, how would I get the same output with data where the width of the whitespace is unknown a priori? I've tried with delim = "" or delim = "\\s" and with trim_ws = TRUE for both with no luck.

library(vroom)
data <- "a   b   c\n 1.0 2.0 3.0\n"
vroom(data, delim = "")
#> Observations: 0
#> Variables: 1
#> chr [1]: a   b   c
#>  1.0 2.0 3.0
#> 
#> 
#> Call `spec()` for a copy-pastable column specification
#> Specify the column types with `col_types` to quiet this message
#> # A tibble: 0 x 1
#> # … with 1 variable: `a b c\n 1.0 2.0 3.0\n` <chr>

vroom(data, delim = "", trim_ws = TRUE)
#> Observations: 0
#> Variables: 1
#> chr [1]: a   b   c
#>  1.0 2.0 3.0
#> 
#> 
#> Call `spec()` for a copy-pastable column specification
#> Specify the column types with `col_types` to quiet this message
#> # A tibble: 0 x 1
#> # … with 1 variable: `a b c\n 1.0 2.0 3.0\n` <chr>

vroom(data, delim = "\\s")
#> Observations: 1
#> Variables: 1
#> chr [1]: a   b   c
#> 
#> Call `spec()` for a copy-pastable column specification
#> Specify the column types with `col_types` to quiet this message
#> # A tibble: 1 x 1
#>   `a   b   c`
#>   <chr>      
#> 1 1.0 2.0 3.0

vroom(data, delim = "\\s", trim_ws = TRUE)
#> Observations: 1
#> Variables: 1
#> chr [1]: a   b   c
#> 
#> Call `spec()` for a copy-pastable column specification
#> Specify the column types with `col_types` to quiet this message
#> # A tibble: 1 x 1
#>   `a   b   c`
#>   <chr>      
#> 1 1.0 2.0 3.0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.