Don't transform non-crossref links

This commit is contained in:
Hadley Wickham
2022-11-18 10:30:32 -06:00
parent 4caea5281b
commit 78a1c12fe7
32 changed files with 693 additions and 693 deletions

View File

@@ -35,12 +35,12 @@ library(tidyverse)</pre>
Getting started</h2>
<p>Most of readxls functions allow you to load Excel spreadsheets into R:</p>
<ul><li>
<code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> reads Excel files with <code>xls</code> format.</li>
<code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_xls()</a></code> reads Excel files with <code>xls</code> format.</li>
<li>
<code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> read Excel files with <code>xlsx</code> format.</li>
<code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_xlsx()</a></code> read Excel files with <code>xlsx</code> format.</li>
<li>
<code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> can read files with both <code>xls</code> and <code>xlsx</code> format. It guesses the file type based on the input.</li>
</ul><p>These functions all have similar syntax just like other functions we have previously introduced for reading other types of files, e.g. <code><a href="#chp-https://readr.tidyverse.org/reference/read_delim" data-type="xref">#chp-https://readr.tidyverse.org/reference/read_delim</a></code>, <code><a href="#chp-https://readr.tidyverse.org/reference/read_table" data-type="xref">#chp-https://readr.tidyverse.org/reference/read_table</a></code>, etc. For the rest of the chapter we will focus on using <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code>.</p>
<code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code> can read files with both <code>xls</code> and <code>xlsx</code> format. It guesses the file type based on the input.</li>
</ul><p>These functions all have similar syntax just like other functions we have previously introduced for reading other types of files, e.g. <code><a href="https://readr.tidyverse.org/reference/read_delim.html">read_csv()</a></code>, <code><a href="https://readr.tidyverse.org/reference/read_table.html">read_table()</a></code>, etc. For the rest of the chapter we will focus on using <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code>.</p>
</section>
<section id="sec-reading-spreadsheets" data-type="sect2">
@@ -55,11 +55,11 @@ Reading spreadsheets</h2>
</figure>
</div>
</div>
<p>The first argument to <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> is the path to the file to read.</p>
<p>The first argument to <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code> is the path to the file to read.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">students &lt;- read_excel("data/students.xlsx")</pre>
</div>
<p><code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> will read the file in as a tibble.</p>
<p><code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code> will read the file in as a tibble.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">students
#&gt; # A tibble: 6 × 5
@@ -130,7 +130,7 @@ Reading spreadsheets</h2>
</div>
</li>
<li>
<p>One other remaining issue is that <code>age</code> is read in as a character variable, but it really should be numeric. Just like with <code><a href="#chp-https://readr.tidyverse.org/reference/read_delim" data-type="xref">#chp-https://readr.tidyverse.org/reference/read_delim</a></code> and friends for reading data from flat files, you can supply a <code>col_types</code> argument to <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> and specify the column types for the variables you read in. The syntax is a bit different, though. Your options are <code>"skip"</code>, <code>"guess"</code>, <code>"logical"</code>, <code>"numeric"</code>, <code>"date"</code>, <code>"text"</code> or <code>"list"</code>.</p>
<p>One other remaining issue is that <code>age</code> is read in as a character variable, but it really should be numeric. Just like with <code><a href="https://readr.tidyverse.org/reference/read_delim.html">read_csv()</a></code> and friends for reading data from flat files, you can supply a <code>col_types</code> argument to <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code> and specify the column types for the variables you read in. The syntax is a bit different, though. Your options are <code>"skip"</code>, <code>"guess"</code>, <code>"logical"</code>, <code>"numeric"</code>, <code>"date"</code>, <code>"text"</code> or <code>"list"</code>.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">read_excel(
"data/students.xlsx",
@@ -193,7 +193,7 @@ Reading individual sheets</h2>
</figure>
</div>
</div>
<p>You can read a single sheet from a spreadsheet with the <code>sheet</code> argument in <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code>.</p>
<p>You can read a single sheet from a spreadsheet with the <code>sheet</code> argument in <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code>.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">read_excel("data/penguins.xlsx", sheet = "Torgersen Island")
#&gt; # A tibble: 52 × 8
@@ -225,12 +225,12 @@ penguins_torgersen
#&gt; # … with 46 more rows, and abbreviated variable names ¹flipper_length_mm,
#&gt; # ²body_mass_g</pre>
</div>
<p>However, we cheated here a bit. We looked inside the Excel spreadsheet, which is not a recommended workflow. Instead, you can use <code><a href="#chp-https://readxl.tidyverse.org/reference/excel_sheets" data-type="xref">#chp-https://readxl.tidyverse.org/reference/excel_sheets</a></code> to get information on all sheets in an Excel spreadsheet, and then read the one(s) youre interested in.</p>
<p>However, we cheated here a bit. We looked inside the Excel spreadsheet, which is not a recommended workflow. Instead, you can use <code><a href="https://readxl.tidyverse.org/reference/excel_sheets.html">excel_sheets()</a></code> to get information on all sheets in an Excel spreadsheet, and then read the one(s) youre interested in.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">excel_sheets("data/penguins.xlsx")
#&gt; [1] "Torgersen Island" "Biscoe Island" "Dream Island"</pre>
</div>
<p>Once you know the names of the sheets, you can read them in individually with <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code>.</p>
<p>Once you know the names of the sheets, you can read them in individually with <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code>.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">penguins_biscoe &lt;- read_excel("data/penguins.xlsx", sheet = "Biscoe Island", na = "NA")
penguins_dream &lt;- read_excel("data/penguins.xlsx", sheet = "Dream Island", na = "NA")</pre>
@@ -244,7 +244,7 @@ dim(penguins_biscoe)
dim(penguins_dream)
#&gt; [1] 124 8</pre>
</div>
<p>We can put them together with <code><a href="#chp-https://dplyr.tidyverse.org/reference/bind_rows" data-type="xref">#chp-https://dplyr.tidyverse.org/reference/bind_rows</a></code>.</p>
<p>We can put them together with <code><a href="https://dplyr.tidyverse.org/reference/bind_rows.html">bind_rows()</a></code>.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">penguins &lt;- bind_rows(penguins_torgersen, penguins_biscoe, penguins_dream)
penguins
@@ -275,7 +275,7 @@ Reading part of a sheet</h2>
</figure>
</div>
</div>
<p>This spreadsheet is one of the example spreadsheets provided in the readxl package. You can use the <code><a href="#chp-https://readxl.tidyverse.org/reference/readxl_example" data-type="xref">#chp-https://readxl.tidyverse.org/reference/readxl_example</a></code> function to locate the spreadsheet on your system in the directory where the package is installed. This function returns the path to the spreadsheet, which you can use in <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code> as usual.</p>
<p>This spreadsheet is one of the example spreadsheets provided in the readxl package. You can use the <code><a href="https://readxl.tidyverse.org/reference/readxl_example.html">readxl_example()</a></code> function to locate the spreadsheet on your system in the directory where the package is installed. This function returns the path to the spreadsheet, which you can use in <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_excel()</a></code> as usual.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">deaths_path &lt;- readxl_example("deaths.xlsx")
deaths &lt;- read_excel(deaths_path)
@@ -389,7 +389,7 @@ bake_sale
#&gt; 2 cupcake 5
#&gt; 3 cookie 8</pre>
</div>
<p>You can write data back to disk as an Excel file using the <code><a href="#chp-https://docs.ropensci.org/writexl/reference/write_xlsx" data-type="xref">#chp-https://docs.ropensci.org/writexl/reference/write_xlsx</a></code> from the <strong>writexl</strong> package.</p>
<p>You can write data back to disk as an Excel file using the <code><a href="https://docs.ropensci.org/writexl/reference/write_xlsx.html">write_xlsx()</a></code> from the <strong>writexl</strong> package.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">library(writexl)
write_xlsx(bake_sale, path = "data/bake-sale.xlsx")</pre>
@@ -469,7 +469,7 @@ writeDataTable(
#&gt; Active Sheet 1: "Adelie"
#&gt; Position: 1</pre>
</div>
<p>And we can write this to this with <code><a href="#chp-https://rdrr.io/pkg/openxlsx/man/saveWorkbook" data-type="xref">#chp-https://rdrr.io/pkg/openxlsx/man/saveWorkbook</a></code>.</p>
<p>And we can write this to this with <code><a href="https://rdrr.io/pkg/openxlsx/man/saveWorkbook.html">saveWorkbook()</a></code>.</p>
<div class="cell">
<pre data-type="programlisting" data-code-language="downlit">saveWorkbook(penguins_species, "data/penguins-species.xlsx")</pre>
</div>
@@ -488,8 +488,8 @@ writeDataTable(
<section id="exercises" data-type="sect2">
<h2>
Exercises</h2>
<ol type="1"><li>Recreate the <code>bake_sale</code> data frame, write it out to an Excel file using the <code><a href="#chp-https://rdrr.io/pkg/openxlsx/man/write.xlsx" data-type="xref">#chp-https://rdrr.io/pkg/openxlsx/man/write.xlsx</a></code> function from the openxlsx package.</li>
<li>What happens if you try to read in a file with <code>.xlsx</code> extension with <code><a href="#chp-https://readxl.tidyverse.org/reference/read_excel" data-type="xref">#chp-https://readxl.tidyverse.org/reference/read_excel</a></code>?</li>
<ol type="1"><li>Recreate the <code>bake_sale</code> data frame, write it out to an Excel file using the <code><a href="https://rdrr.io/pkg/openxlsx/man/write.xlsx.html">write.xlsx()</a></code> function from the openxlsx package.</li>
<li>What happens if you try to read in a file with <code>.xlsx</code> extension with <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">read_xls()</a></code>?</li>
</ol><!--# Need moar exercises --></section>
</section>