From f957bb0f3b6f46f7f9780a8762018d65088b4a8a Mon Sep 17 00:00:00 2001 From: maurolepore Date: Mon, 7 Jan 2019 22:33:14 -0500 Subject: [PATCH] Update readme. --- README.Rmd | 2 +- README.md | 2 +- docs/index.html | 96 +++++++++++++++++++-------------- docs/news/index.html | 5 ++ docs/reference/format_path.html | 18 ++++--- docs/reference/list_any.html | 34 +++++++----- docs/reference/list_csv.html | 28 ++++++---- docs/reference/load_csv.html | 16 +++--- 8 files changed, 122 insertions(+), 79 deletions(-) diff --git a/README.Rmd b/README.Rmd index 0934346..7db0512 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,7 +39,7 @@ library(fs) library(tor) ``` -All functions list whatever they read, and default to reading from the working directory. +All functions list whatever they read, and default to reading from the working directory. Dataframes are coerced to tibbles. ### `list_*()`: Import multiple files from a directory into a list diff --git a/README.md b/README.md index 45c50f7..4495223 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ library(tor) ``` All functions list whatever they read, and default to reading from the -working directory. +working directory. Dataframes are coerced to tibbles. ### `list_*()`: Import multiple files from a directory into a list diff --git a/docs/index.html b/docs/index.html index 3026957..40881ec 100644 --- a/docs/index.html +++ b/docs/index.html @@ -102,7 +102,7 @@

#> x dplyr::lag() masks stats::lag() library(fs) library(tor) -

All functions list whatever they read, and default to reading from the working directory.

+

All functions list whatever they read, and default to reading from the working directory. Dataframes are coerced to tibbles.

list_*(): Import multiple files from a directory into a list

@@ -117,14 +117,18 @@

list_csv() #> $csv1 -#> x -#> 1 1 -#> 2 2 -#> -#> $csv2 -#> y -#> 1 a -#> 2 b

+#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 +#> +#> $csv2 +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b

Often you will specify a path to read from.

+#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 +#> +#> $csv2 +#> # A tibble: 2 x 1 +#> y +#> <fct> +#> 1 a +#> 2 b

It understands lambda functions and formulas (powered by rlang).

+#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 +csv2 +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b

You may load from a path.

+#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 +#> +#> $csv2 +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b + +paths <- dfs %>% + imap_chr(~ format_path(.y, "csv", base = ".", prefix = "this-")) + +walk2(dfs, paths, readr::write_csv) + +dir_ls(".", regexp = "this-") +#> this-csv1.csv this-csv2.csv diff --git a/docs/news/index.html b/docs/news/index.html index 096a017..f91d1a6 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -110,6 +110,11 @@

Minor

diff --git a/docs/reference/format_path.html b/docs/reference/format_path.html index c9512c3..56b384c 100644 --- a/docs/reference/format_path.html +++ b/docs/reference/format_path.html @@ -139,17 +139,21 @@

See a

Examples

format_path(c("file1", "file2"), "csv")
#> [1] "./file1.csv" "./file2.csv"
(dfs <- list_csv(tor_example("csv")))
#> $csv1 -#> x -#> 1 1 -#> 2 2 +#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 #> #> $csv2 -#> y -#> 1 a -#> 2 b +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b #>
format_path(names(dfs), "csv")
#> [1] "./csv1.csv" "./csv2.csv"
-format_path(names(dfs), "csv", base = "home", prefix = "this-")
#> [1] "home/this-csv1.csv" "home/this-csv2.csv"
+format_path(names(dfs), "csv", base = "home", prefix = "this-")
#> [1] "home/this-csv1.csv" "home/this-csv2.csv"
#> [1] "csv1.csv" "csv2.csv"
list_any(path, read.csv)
#> $csv1 -#> x -#> 1 1 -#> 2 2 +#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 #> #> $csv2 -#> y -#> 1 a -#> 2 b +#> # A tibble: 2 x 1 +#> y +#> <fct> +#> 1 a +#> 2 b #>
list_any(path, ~ read.csv(.x, stringsAsFactors = FALSE))
#> $csv1 -#> x -#> 1 1 -#> 2 2 +#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2 #> #> $csv2 -#> y -#> 1 a -#> 2 b +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b #>
(path_mixed <- tor_example("mixed"))
#> [1] "C:/Users/LeporeM/Documents/Dropbox/git/ml/tor/inst/extdata/mixed"
dir(path_mixed)
#> [1] "csv.csv" "lower_rdata.rdata" "rda.rda" #> [4] "upper_rdata.RData"
@@ -187,7 +195,7 @@

Examp regexp = "[.]csv$", invert = TRUE )

#> $lower_rdata -#> # A tibble: 2 x 1 +#> # A tibble: 2 x 1 #> y #> <chr> #> 1 a diff --git a/docs/reference/list_csv.html b/docs/reference/list_csv.html index 41fef13..333b8c7 100644 --- a/docs/reference/list_csv.html +++ b/docs/reference/list_csv.html @@ -236,16 +236,20 @@

Examp #>

(tsv <- tor_example("tsv"))
#> [1] "C:/Users/LeporeM/Documents/Dropbox/git/ml/tor/inst/extdata/tsv"
dir(tsv)
#> [1] "tsv1.tsv" "tsv2.tsv"
list_tsv(tsv)
#> $tsv1 -#> x y -#> 1 1 a -#> 2 2 <NA> -#> 3 3 <NA> +#> # A tibble: 3 x 2 +#> x y +#> <int> <chr> +#> 1 1 a +#> 2 2 NA +#> 3 3 NA #> #> $tsv2 -#> x y -#> 1 1 a -#> 2 2 <NA> -#> 3 3 b +#> # A tibble: 3 x 2 +#> x y +#> <int> <chr> +#> 1 1 a +#> 2 2 NA +#> 3 3 b #>
(mixed <- tor_example("mixed"))
#> [1] "C:/Users/LeporeM/Documents/Dropbox/git/ml/tor/inst/extdata/mixed"
dir(mixed)
#> [1] "csv.csv" "lower_rdata.rdata" "rda.rda" #> [4] "upper_rdata.RData"
@@ -271,9 +275,11 @@

Examp #> 2 b #>

list_csv(mixed)
#> $csv -#> y -#> 1 a -#> 2 b +#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b #>
list_rdata(mixed, regexp = "[.]RData", ignore.case = FALSE)
#> $upper_rdata #> # A tibble: 2 x 1 diff --git a/docs/reference/load_csv.html b/docs/reference/load_csv.html index 09e008e..3439092 100644 --- a/docs/reference/load_csv.html +++ b/docs/reference/load_csv.html @@ -228,16 +228,20 @@

Examp
(path_csv <- tor_example("csv"))
#> [1] "C:/Users/LeporeM/Documents/Dropbox/git/ml/tor/inst/extdata/csv"
dir(path_csv)
#> [1] "csv1.csv" "csv2.csv"
load_csv(path_csv) # Each dataframe is now available in the global environment -csv1
#> x -#> 1 1 -#> 2 2
csv2
#> y -#> 1 a -#> 2 b
+csv1
#> # A tibble: 2 x 1 +#> x +#> <int> +#> 1 1 +#> 2 2
csv2
#> # A tibble: 2 x 1 +#> y +#> <chr> +#> 1 a +#> 2 b
(path_mixed <- tor_example("mixed"))
#> [1] "C:/Users/LeporeM/Documents/Dropbox/git/ml/tor/inst/extdata/mixed"
dir(path_mixed)
#> [1] "csv.csv" "lower_rdata.rdata" "rda.rda" #> [4] "upper_rdata.RData"
load_rdata(path_mixed) # Each dataframe is now available in the global environment -lower_rdata
#> # A tibble: 2 x 1 +lower_rdata
#> # A tibble: 2 x 1 #> y #> <chr> #> 1 a