17  R语言基础

library(tidyverse)
#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
#> ✔ dplyr     1.1.2     ✔ readr     2.1.4
#> ✔ forcats   1.0.0     ✔ stringr   1.5.0
#> ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
#> ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
#> ✔ purrr     1.0.1     
#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag()    masks stats::lag()
#> ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
mtcars %>% head()
#>                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
#> Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
Extension Engine Binding
.qmd Use Knitr engine if an {r} code block is discovered within the fileUse Jupyter engine if any other executable code block (e.g. {python}, {julia}, {bash}, etc.) is discovered within the file. The kernel used is determined based on the language of the first executable code block discovered.Use no engine if no executable code blocks are discovered.
.ipynb Jupyter engine
.Rmd Knitr engine
.md No engine (note that if an md document does contain executable code blocks then an error will occur)

You can override the engine used via the engine option. For example:

engine: jupyter
engine: knitr

You can also specify that no execution engine should be used via engine: markdown.

The presence of the knitr or jupyter option will also override the default engine:

knitr: true
jupyter: python3

Variations with additional engine-specific options also work to override the default engine:

knitr:
  opts_knit:
    verbose: true
jupyter:
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
echo "foo"
#> foo