Session - Code Chunks
Ctrl + Alt + i
/
Running a chunk
Play
an individual chunk with the green triangleRender
button to run all chunks and produce the outputCtrl + Shift + Enter
Let’s see the fate of this chunk…
# A tibble: 1 × 1
total
<int>
1 350
Tibble?
This is a view of the data that would normally go to the Console when run as a chunk so includes information like data types (A tibble:...
).
What happens here if we create an object?
Nothing shows!
With echo: false
there is no code and even with eval: true
it has run but there is no output to see - why?
Can we now see the results?
# A tibble: 1 × 1
total
<int>
1 350
Metadata is still showing!
The information about the table is still showing (A tibble:...
)
Tables are the output of data (not data frames which are data object types)
date_reported | continent | countries_and_territories | country_territory_code | population_2019 | cases | deaths |
---|---|---|---|---|---|---|
2020-12-14 | Asia | Afghanistan | AFG | 38041757 | 746 | 6 |
2020-12-13 | Asia | Afghanistan | AFG | 38041757 | 298 | 9 |
2020-12-12 | Asia | Afghanistan | AFG | 38041757 | 113 | 11 |
2020-12-11 | Asia | Afghanistan | AFG | 38041757 | 63 | 10 |
2020-12-10 | Asia | Afghanistan | AFG | 38041757 | 202 | 16 |
Default option
When nothing is set all options are true.
Code, messages, warnings are shown and the code is “evaluated” (it breaks if there is a bug).
Rows: 61,900
Columns: 7
$ date_reported <date> 2020-12-14, 2020-12-13, 2020-12-12, 2020-12…
$ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, As…
$ countries_and_territories <fct> "Afghanistan", "Afghanistan", "Afghanistan",…
$ country_territory_code <fct> AFG, AFG, AFG, AFG, AFG, AFG, AFG, AFG, AFG,…
$ population_2019 <int> 38041757, 38041757, 38041757, 38041757, 3804…
$ cases <int> 746, 298, 113, 63, 202, 135, 200, 210, 234, …
$ deaths <int> 6, 9, 11, 10, 16, 13, 6, 26, 10, 18, 5, 19, …
#| echo
Echo shows the code and when it’s set to false
code is hidden
Rows: 61,900
Columns: 7
$ date_reported <date> 2020-12-14, 2020-12-13, 2020-12-12, 2020-12…
$ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, As…
$ countries_and_territories <fct> "Afghanistan", "Afghanistan", "Afghanistan",…
$ country_territory_code <fct> AFG, AFG, AFG, AFG, AFG, AFG, AFG, AFG, AFG,…
$ population_2019 <int> 38041757, 38041757, 38041757, 38041757, 3804…
$ cases <int> 746, 298, 113, 63, 202, 135, 200, 210, 234, …
$ deaths <int> 6, 9, 11, 10, 16, 13, 6, 26, 10, 18, 5, 19, …
#| eval
eval
is short for evaluate which means the code is run. If there is a bug the report won’t run.
#| include
include
default is true and when set to false will prevent any output (code or results) from being included in the output.
This includes the {tidyverse} message.
The code is still run and available to subsequent chunks.
This can be done in chunks:
More details are online in the Quarto documentation
#|
which has no short cut key currently…Don’t repeat labels!
ref-label:
can also be used instead of label:
Erroring:
processing file: covid-report.qmd
Error in parse_block(g[-1], g[1], params.src, markdown_mode) :
Duplicate chunk label 'covid-chart', which has been used for the chunk:
library(tidyverse)
library(NHSRdatasets)
local_covid <- NHSRdatasets::covid19 |>
filter(countries_and_territories == params$site)
Calls: .main ... process_file -> split_file -> lapply -> FUN -> parse_block
Execution halted
In the report covid-analysis.qmd
:
label: test
ref-label: test
eval:
and echo:
, render and see the difference08:00
Chunk options can be set once at the YAML and to apply the whole report.