Skip to content

Commit 35a1905

Browse files
fontikarjennybc
andauthored
Don't mention iris dataset in documentation (#752)
* Removed iris from dataset.xlsx * Removed iris from datasets.xls * Remove mention of iris in README files #642 * Removed mentioning of iris in vignettes, using mtcars instead * Updated examples to refer to new mtcars instead of iris * Updated example to better illustrate example in helpfile * Whitespace --------- Co-authored-by: Jenny Bryan <[email protected]>
1 parent 22ded0b commit 35a1905

File tree

9 files changed

+79
-71
lines changed

9 files changed

+79
-71
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ Config/testthat/edition: 3
5050
Encoding: UTF-8
5151
Note: libxls v1.6.2 (patched) 45abe77
5252
Roxygen: list(markdown = TRUE)
53-
RoxygenNote: 7.2.3
53+
RoxygenNote: 7.3.2

R/read_excel.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ NULL
5757
#' read_excel(datasets, "mtcars")
5858
#'
5959
#' # Skip rows and use default column names
60-
#' read_excel(datasets, skip = 148, col_names = FALSE)
60+
#' read_excel(datasets, skip = 10, col_names = FALSE)
6161
#'
6262
#' # Recycle a single column type
6363
#' read_excel(datasets, col_types = "text")
6464
#'
6565
#' # Specify some col_types and guess others
66-
#' read_excel(datasets, col_types = c("text", "guess", "numeric", "guess", "guess"))
66+
#' read_excel(
67+
#' readxl_example("deaths.xlsx"),
68+
#' skip = 4, n_max = 10, col_names = TRUE,
69+
#' col_types = c("text", "text", "guess", "guess", "guess", "guess")
70+
#' )
6771
#'
6872
#' # Accomodate a column with disparate types via col_type = "list"
6973
#' df <- read_excel(readxl_example("clippy.xlsx"), col_types = c("text", "list"))

README.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Specify a worksheet by name or number.
9393

9494
```{r}
9595
read_excel(xlsx_example, sheet = "chickwts")
96-
read_excel(xls_example, sheet = 4)
96+
read_excel(xls_example, sheet = 3)
9797
```
9898

9999
There are various ways to control which cells are read. You can even specify the sheet here, if providing an Excel-style cell range.
@@ -109,7 +109,7 @@ read_excel(xlsx_example, range = "mtcars!B1:D5")
109109
If `NA`s are represented by something other than blank cells, set the `na` argument.
110110

111111
```{r}
112-
read_excel(xlsx_example, na = "setosa")
112+
read_excel(xlsx_example, na = "0")
113113
```
114114

115115
If you are new to the tidyverse conventions for data import, you may want to consult the [data import chapter](https://r4ds.had.co.nz/data-import.html) in R for Data Science. readxl will become increasingly consistent with other packages, such as [readr](https://readr.tidyverse.org/).
@@ -149,7 +149,7 @@ Here are some other packages with functionality that is complementary to readxl
149149
__Writing Excel files__: The example files `datasets.xlsx` and `datasets.xls` were created with the help of [openxlsx](https://CRAN.R-project.org/package=openxlsx) (and Excel). openxlsx provides "a high level interface to writing, styling and editing worksheets".
150150

151151
```{r eval = FALSE}
152-
l <- list(iris = iris, mtcars = mtcars, chickwts = chickwts, quakes = quakes)
152+
l <- list(mtcars = mtcars, chickwts = chickwts, quakes = quakes)
153153
openxlsx::write.xlsx(l, file = "inst/extdata/datasets.xlsx")
154154
```
155155

README.md

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ readxl_example()
7575
#> [5] "deaths.xls" "deaths.xlsx" "geometry.xls" "geometry.xlsx"
7676
#> [9] "type-me.xls" "type-me.xlsx"
7777
readxl_example("clippy.xls")
78-
#> [1] "/private/tmp/RtmpM1GkLC/temp_libpatha8e46f7f62bf/readxl/extdata/clippy.xls"
78+
#> [1] "/Users/fontikar/Library/R/arm64/4.4/library/readxl/extdata/clippy.xls"
7979
```
8080

8181
`read_excel()` reads both xls and xlsx files and detects the format from
@@ -84,30 +84,30 @@ the extension.
8484
``` r
8585
xlsx_example <- readxl_example("datasets.xlsx")
8686
read_excel(xlsx_example)
87-
#> # A tibble: 150 × 5
88-
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
89-
#> <dbl> <dbl> <dbl> <dbl> <chr>
90-
#> 1 5.1 3.5 1.4 0.2 setosa
91-
#> 2 4.9 3 1.4 0.2 setosa
92-
#> 3 4.7 3.2 1.3 0.2 setosa
93-
#> # ℹ 147 more rows
87+
#> # A tibble: 32 × 11
88+
#> mpg cyl disp hp drat wt qsec vs am gear carb
89+
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
90+
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
91+
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
92+
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
93+
#> # ℹ 29 more rows
9494

9595
xls_example <- readxl_example("datasets.xls")
9696
read_excel(xls_example)
97-
#> # A tibble: 150 × 5
98-
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
99-
#> <dbl> <dbl> <dbl> <dbl> <chr>
100-
#> 1 5.1 3.5 1.4 0.2 setosa
101-
#> 2 4.9 3 1.4 0.2 setosa
102-
#> 3 4.7 3.2 1.3 0.2 setosa
103-
#> # ℹ 147 more rows
97+
#> # A tibble: 32 × 11
98+
#> mpg cyl disp hp drat wt qsec vs am gear carb
99+
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
100+
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
101+
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
102+
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
103+
#> # ℹ 29 more rows
104104
```
105105

106106
List the sheet names with `excel_sheets()`.
107107

108108
``` r
109109
excel_sheets(xlsx_example)
110-
#> [1] "iris" "mtcars" "chickwts" "quakes"
110+
#> [1] "mtcars" "chickwts" "quakes"
111111
```
112112

113113
Specify a worksheet by name or number.
@@ -121,7 +121,7 @@ read_excel(xlsx_example, sheet = "chickwts")
121121
#> 2 160 horsebean
122122
#> 3 136 horsebean
123123
#> # ℹ 68 more rows
124-
read_excel(xls_example, sheet = 4)
124+
read_excel(xls_example, sheet = 3)
125125
#> # A tibble: 1,000 × 5
126126
#> lat long depth mag stations
127127
#> <dbl> <dbl> <dbl> <dbl> <dbl>
@@ -136,34 +136,34 @@ specify the sheet here, if providing an Excel-style cell range.
136136

137137
``` r
138138
read_excel(xlsx_example, n_max = 3)
139-
#> # A tibble: 3 × 5
140-
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
141-
#> <dbl> <dbl> <dbl> <dbl> <chr>
142-
#> 1 5.1 3.5 1.4 0.2 setosa
143-
#> 2 4.9 3 1.4 0.2 setosa
144-
#> 3 4.7 3.2 1.3 0.2 setosa
139+
#> # A tibble: 3 × 11
140+
#> mpg cyl disp hp drat wt qsec vs am gear carb
141+
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
142+
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
143+
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
144+
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
145145
read_excel(xlsx_example, range = "C1:E4")
146146
#> # A tibble: 3 × 3
147-
#> Petal.Length Petal.Width Species
148-
#> <dbl> <dbl> <chr>
149-
#> 1 1.4 0.2 setosa
150-
#> 2 1.4 0.2 setosa
151-
#> 3 1.3 0.2 setosa
147+
#> disp hp drat
148+
#> <dbl> <dbl> <dbl>
149+
#> 1 160 110 3.9
150+
#> 2 160 110 3.9
151+
#> 3 108 93 3.85
152152
read_excel(xlsx_example, range = cell_rows(1:4))
153-
#> # A tibble: 3 × 5
154-
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
155-
#> <dbl> <dbl> <dbl> <dbl> <chr>
156-
#> 1 5.1 3.5 1.4 0.2 setosa
157-
#> 2 4.9 3 1.4 0.2 setosa
158-
#> 3 4.7 3.2 1.3 0.2 setosa
153+
#> # A tibble: 3 × 11
154+
#> mpg cyl disp hp drat wt qsec vs am gear carb
155+
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
156+
#> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4
157+
#> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4
158+
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
159159
read_excel(xlsx_example, range = cell_cols("B:D"))
160-
#> # A tibble: 150 × 3
161-
#> Sepal.Width Petal.Length Petal.Width
162-
#> <dbl> <dbl> <dbl>
163-
#> 1 3.5 1.4 0.2
164-
#> 2 3 1.4 0.2
165-
#> 3 3.2 1.3 0.2
166-
#> # ℹ 147 more rows
160+
#> # A tibble: 32 × 3
161+
#> cyl disp hp
162+
#> <dbl> <dbl> <dbl>
163+
#> 1 6 160 110
164+
#> 2 6 160 110
165+
#> 3 4 108 93
166+
#> # ℹ 29 more rows
167167
read_excel(xlsx_example, range = "mtcars!B1:D5")
168168
#> # A tibble: 4 × 3
169169
#> cyl disp hp
@@ -178,14 +178,14 @@ If `NA`s are represented by something other than blank cells, set the
178178
`na` argument.
179179

180180
``` r
181-
read_excel(xlsx_example, na = "setosa")
182-
#> # A tibble: 150 × 5
183-
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
184-
#> <dbl> <dbl> <dbl> <dbl> <chr>
185-
#> 1 5.1 3.5 1.4 0.2 <NA>
186-
#> 2 4.9 3 1.4 0.2 <NA>
187-
#> 3 4.7 3.2 1.3 0.2 <NA>
188-
#> # ℹ 147 more rows
181+
read_excel(xlsx_example, na = "0")
182+
#> # A tibble: 32 × 11
183+
#> mpg cyl disp hp drat wt qsec vs am gear carb
184+
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
185+
#> 1 21 6 160 110 3.9 2.62 16.5 NA 1 4 4
186+
#> 2 21 6 160 110 3.9 2.88 17.0 NA 1 4 4
187+
#> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
188+
#> # ℹ 29 more rows
189189
```
190190

191191
If you are new to the tidyverse conventions for data import, you may
@@ -249,7 +249,7 @@ openxlsx provides “a high level interface to writing, styling and
249249
editing worksheets”.
250250

251251
``` r
252-
l <- list(iris = iris, mtcars = mtcars, chickwts = chickwts, quakes = quakes)
252+
l <- list(mtcars = mtcars, chickwts = chickwts, quakes = quakes)
253253
openxlsx::write.xlsx(l, file = "inst/extdata/datasets.xlsx")
254254
```
255255

inst/extdata/datasets.xls

6.5 KB
Binary file not shown.

inst/extdata/datasets.xlsx

-9.95 KB
Binary file not shown.

inst/extdata/deaths.xls

0 Bytes
Binary file not shown.

man/read_excel.Rd

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/articles/readxl-workflows.Rmd

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,32 @@ Solution: cache a CSV snapshot of your raw data tables at the time of export. Ev
4747
Pipe the output of `read_excel()` directly into `readr::write_csv()` like so:
4848

4949
```{r}
50-
iris_xl <- readxl_example("datasets.xlsx") %>%
51-
read_excel(sheet = "iris") %>%
52-
write_csv("iris-raw.csv")
50+
mtcars_xl <- readxl_example("datasets.xlsx") %>%
51+
read_excel(sheet = "mtcars") %>%
52+
write_csv("mtcars-raw.csv")
5353
```
5454

5555
```{r include = FALSE}
56-
delete_on_exit <- c(delete_on_exit, "iris-raw.csv")
56+
delete_on_exit <- c(delete_on_exit, "mtcars-raw.csv")
5757
```
5858

5959
Why does this work? `readr::write_csv()` is a well-mannered "write" function: it does its main job *and returns its input invisibly*. The above command reads the iris sheet from readxl's `datasets.xlsx` example workbook and caches a CSV version of the resulting data frame to file.
6060

6161
Let's check. Did we still import the data? Did we write the CSV file?
6262

6363
```{r}
64-
iris_xl
65-
dir(pattern = "iris")
64+
mtcars_xl
65+
dir(pattern = "mtcars")
6666
```
6767

6868
Yes! Is the data written to CSV an exact copy of what we imported from Excel?
6969

7070
```{r}
71-
iris_alt <- read_csv("iris-raw.csv")
71+
mtcars_alt <- read_csv("mtcars-raw.csv")
7272
## readr leaves a note-to-self in `spec` that records its column guessing,
7373
## so we remove that attribute before the check
74-
attr(iris_alt, "spec") <- NULL
75-
identical(iris_xl, iris_alt)
74+
attr(mtcars_alt, "spec") <- NULL
75+
identical(mtcars_xl, mtcars_alt)
7676
```
7777

7878
Yes! If we needed to restart or troubleshoot this fictional analysis, `iris-raw.csv` is available as a second, highly accessible alternative to `datasets.xlsx`.
@@ -193,11 +193,11 @@ Rework examples from above but using base R only, other than readxl.
193193
### Cache a CSV snapshot
194194

195195
```{r eval = FALSE}
196-
iris_xl <- read_excel(readxl_example("datasets.xlsx"), sheet = "iris")
197-
write.csv(iris_xl, "iris-raw.csv", row.names = FALSE, quote = FALSE)
198-
iris_alt <- read.csv("iris-raw.csv", stringsAsFactors = FALSE)
196+
mtcars_xl <- read_excel(readxl_example("datasets.xlsx"), sheet = "mtcars")
197+
write.csv(iris_xl, "mtcars-raw.csv", row.names = FALSE, quote = FALSE)
198+
mtcars_alt <- read.csv("mtcars-raw.csv", stringsAsFactors = FALSE)
199199
## coerce iris_xl back to a data.frame
200-
identical(as.data.frame(iris_xl), iris_alt)
200+
identical(as.data.frame(mtcars_xl), mtcars_alt)
201201
```
202202

203203
### Iterate over multiple worksheets in a workbook

0 commit comments

Comments
 (0)