R knitr';s构建代码附录不起作用
我正在尝试使用下面一惠网站的说明构建代码附录: 问题是我没有得到任何结果,在RStudio中预览代码时什么都没有发生。我注意到的一件事是,codeR knitr';s构建代码附录不起作用,r,knitr,R,Knitr,我正在尝试使用下面一惠网站的说明构建代码附录: 问题是我没有得到任何结果,在RStudio中预览代码时什么都没有发生。我注意到的一件事是,codeknitr::all_labels()返回NULL,即使我在我的笔记本中已经命名了所有30多个块。此外,我还能够使用purl构建一个外部文件,这是最后一行。我试图用一个基本的入门Rnotebook构建一个reprex,但是reprex没有在RStudio中构建,所以我将粘贴尝试的内容 谢谢大家! 代码…抱歉,我必须删除背面的记号,这样我才能将所有代码
knitr::all_labels()
返回NULL
,即使我在我的笔记本中已经命名了所有30多个块。此外,我还能够使用purl
构建一个外部文件,这是最后一行。我试图用一个基本的入门Rnotebook构建一个reprex,但是reprex没有在RStudio中构建,所以我将粘贴尝试的内容
谢谢大家!
代码…抱歉,我必须删除背面的记号,这样我才能将所有代码块粘贴在一起
---
title: "Reprex for Code Appendix"
author: 'ME'
date: "`r Sys.Date()`"
output:
html_notebook:
code_folding: hide
---
{r setup, echo = TRUE}
knitr::opts_chunk$set(
message = FALSE,
warning = FALSE,
# cache = TRUE,
dev.args = list(pointsize = 11)
)
options(digits = 3, width = 80)
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*.
{r test}
plot(cars)
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Ctrl+Alt+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Ctrl+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
# Appendix: All code for this report
{r Code, ref.label=knitr::all_labels(), echo=TRUE}
{r get-labels, echo = FALSE}
labs = knitr::all_labels()
labs = setdiff(labs, c("setup", "get-labels"))
{r all-code, ref.label=labs, eval=FALSE}
{r, ref.label=knitr::all_labels(),echo=TRUE,eval=FALSE}
THIS DID WORK - BUILT A NEW FILE WITH THE CODE!!!!
{r code=readLines(knitr::purl('./Reprex_for_Code_Appendix.Rmd', documentation = 1)), eval = FALSE}
输出:
Reprex for Code Appendix
ME
2020-03-16
knitr::opts_chunk$set(
message = FALSE,
warning = FALSE,
# cache = TRUE,
dev.args = list(pointsize = 11)
)
options(digits = 3, width = 80)
This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
Appendix: All code for this report
THIS DID WORK - BUILT A NEW FILE WITH THE CODE!!!!
sessioninfo::session\u info()
knitr::all_labels()
如果在整个编织过程中未调用它,则返回NULL
。当您在R Markdown笔记本中运行单个代码块时,文档未完全编织
要使
knitr::all_labels()
返回所有区块标签,您不应该使用笔记本模式或预览笔记本,而是编织文档(例如,编织到html_文档
输出格式)。你好,易慧!谢谢你的推荐有效,但我有几个问题需要澄清。首先,附录不仅打印了代码,还生成了输出……有没有办法阻止它这样做?第二,我应该使用Rnotebooks吗?我什么时候会使用html_笔记本和html_文档?谢谢
- Session info -----------------------------------------------------------------
setting value
version R version 3.6.3 (2020-02-29)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.1252
ctype English_United States.1252
tz America/Chicago
date 2020-03-16
- Packages ---------------------------------------------------------------------
package * version date lib source
anomalize 0.2.0 2019-09-21 [1] CRAN (R 3.6.3)
anytime 0.3.7 2020-01-20 [1] CRAN (R 3.6.3)
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.3)
backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0)
bit 1.1-15.2 2020-02-10 [1] CRAN (R 3.6.2)
bit64 0.9-7 2017-05-08 [1] CRAN (R 3.6.2)
blob 1.2.1 2020-01-20 [1] CRAN (R 3.6.3)
broom 0.5.5 2020-02-29 [1] CRAN (R 3.6.3)
callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.3)
cellranger 1.1.0 2016-07-27 [1] CRAN (R 3.6.3)
cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.3)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1)
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.3)
data.table 1.12.8 2019-12-09 [1] CRAN (R 3.6.3)
DBI 1.1.0 2019-12-15 [1] CRAN (R 3.6.3)
dbplyr 1.4.2 2019-06-17 [1] CRAN (R 3.6.3)
desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.3)
devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.3)
digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.3)
dplyr * 0.8.4 2020-01-31 [1] CRAN (R 3.6.3)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.3)
evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.3)
fable * 0.1.2 2020-01-29 [1] CRAN (R 3.6.3)
fabletools * 0.1.2 2020-01-29 [1] CRAN (R 3.6.3)
fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.3)
farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.3)
fastmap 1.0.1 2019-10-08 [1] CRAN (R 3.6.3)
feasts * 0.1.2 2020-01-17 [1] CRAN (R 3.6.3)
forcats * 0.5.0 2020-03-01 [1] CRAN (R 3.6.3)
fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.3)
generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.3)
ggplot2 * 3.3.0 2020-03-05 [1] CRAN (R 3.6.3)
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.3)
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.3)
haven 2.2.0 2019-11-08 [1] CRAN (R 3.6.3)
highr 0.8 2019-03-20 [1] CRAN (R 3.6.3)
hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.3)
htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.3)
httpuv 1.5.2 2019-09-11 [1] CRAN (R 3.6.3)
httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.3)
jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.3)
kableExtra 1.1.0 2019-03-16 [1] CRAN (R 3.6.3)
knitr * 1.28 2020-02-06 [1] CRAN (R 3.6.3)
labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
later 1.0.0 2019-10-04 [1] CRAN (R 3.6.3)
lattice 0.20-38 2018-11-04 [2] CRAN (R 3.6.3)
lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.3)
lubridate 1.7.4 2018-04-11 [1] CRAN (R 3.6.3)
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.3)
memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.3)
mime 0.9 2020-02-04 [1] CRAN (R 3.6.2)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 3.6.3)
modelr 0.1.6 2020-02-22 [1] CRAN (R 3.6.3)
multidplyr 0.0.0.9000 2020-02-29 [1] local
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.3)
nlme 3.1-144 2020-02-06 [2] CRAN (R 3.6.3)
pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.3)
pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.3)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.3)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.3)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.3)
processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.3)
promises 1.1.0 2019-10-04 [1] CRAN (R 3.6.3)
ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.3)
purrr * 0.3.3 2019-10-18 [1] CRAN (R 3.6.3)
R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.3)
Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.3)
readr * 1.3.1 2018-12-21 [1] CRAN (R 3.6.3)
readxl 1.3.1 2019-03-13 [1] CRAN (R 3.6.3)
remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.3)
reprex 0.3.0 2019-05-16 [1] CRAN (R 3.6.3)
rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.3)
rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.3)
RODBC 1.3-16 2019-09-03 [1] CRAN (R 3.6.1)
RPostgres * 1.2.0 2019-12-18 [1] CRAN (R 3.6.3)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.3)
rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.3)
rvest 0.3.5 2019-11-08 [1] CRAN (R 3.6.3)
scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.3)
sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.3)
shiny * 1.4.0 2019-10-10 [1] CRAN (R 3.6.3)
sodium 1.1 2017-03-30 [1] CRAN (R 3.6.3)
stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
stringr * 1.4.0 2019-02-10 [1] CRAN (R 3.6.3)
testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.3)
tibble * 2.1.3 2019-06-06 [1] CRAN (R 3.6.2)
tibbletime 0.1.3 2019-09-20 [1] CRAN (R 3.6.3)
tidyr * 1.0.2 2020-01-24 [1] CRAN (R 3.6.3)
tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.3)
tidyverse * 1.3.0 2019-11-21 [1] CRAN (R 3.6.3)
tsibble * 0.8.6 2020-01-31 [1] CRAN (R 3.6.3)
urca 1.3-0 2016-09-06 [1] CRAN (R 3.6.3)
usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.3)
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.3)
vctrs 0.2.3 2020-02-20 [1] CRAN (R 3.6.3)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.3)
webshot 0.5.2 2019-11-22 [1] CRAN (R 3.6.3)
whisker 0.4 2019-08-28 [1] CRAN (R 3.6.3)
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.3)
xfun 0.12 2020-01-13 [1] CRAN (R 3.6.3)
xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.3)
xtable 1.8-4 2019-04-21 [1] CRAN (R 3.6.3)
yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2)
[1] C:/Apps/R/R_LIBS_USER
[2] C:/Apps/R/R-3.6.3/library