read.str and read_str read the structure printed when utils::str.data.frame() back into a data frame.

read.str(file = clipr::read_clip())

read_str(file = clipr::read_clip())

Arguments

file

Character. A path to a file, a connection, or literal data (either a single string or a vector of lines). If unspecified, reads from the clipboard.

Value

A data frame of the class specified in the first line of input.

Details

read.str and read_str are roughly inverses of str.data.frame, except:

  • read.str subsets to rows where the str results contain the complete data for the observation,

  • attributes are dropped, and

  • list and matrix columns are unsupported.

Classes at the top of the str results are reassigned, so both vanilla data.frames and variants like tbl_df and data.table are supported. Because class is determined by the data, read_str is merely an alias.

Examples

read.str(capture.output(str(iris)))
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5.0 3.4 1.5 0.2 setosa #> 9 4.4 2.9 1.4 0.2 setosa #> 10 4.9 3.1 1.5 0.1 setosa
# Resulting class is determined by input, not read.str vs. read_str read_str(capture.output(str(tibble::as_tibble(iris))))
#> # A tibble: 10 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> * <dbl> <dbl> <dbl> <dbl> <fct> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #> 7 4.6 3.4 1.4 0.3 setosa #> 8 5 3.4 1.5 0.2 setosa #> 9 4.4 2.9 1.4 0.2 setosa #> 10 4.9 3.1 1.5 0.1 setosa