RMarkdown 代码块在预览中有效,但在 "build" with bookdown 时无效
RMarkdown code chunk works in preview but not when "build" with bookdown
我这里有以下 COVID 19 的 Rmarkdown 代码:
library(tidyverse)
# Importiere Johns Hopkins Github data
confirmedraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
deathsraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
recoveredraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")
confirmed <- confirmedraw %>%
gather(key="date", value="confirmed", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>%
summarize(confirmed=sum(confirmed))
deaths <- deathsraw %>%
gather(key="date", value="deaths", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(deaths=sum(deaths))
recovered <- recoveredraw %>%
gather(key="date", value="recovered", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(recovered=sum(recovered))
summary(confirmed)
country <- full_join(confirmed, deaths) %>%
full_join(recovered)
这 运行 在 RStudio 预览和 R 控制台本身中都很好。
但是,如果我尝试使用 bookdown 构建我的书,最后一行中的 full_join()
将失败。
我收到错误:
Error: `by` must be supplied when `x` and `y` have no common variables.
ℹ use by = character()` to perform a cross-join.
Backtrace:
█
1. ├─rmarkdown::render_site(output_format = "bookdown::gitbook", encoding = "UTF-8")
2. │ └─generator$render(...)
3. │ ├─xfun::in_dir(...)
4. │ └─bookdown:::render_book_script(output_format, envir, quiet)
5. │ └─bookdown::render_book(...)
6. │ └─bookdown:::render_cur_session(...)
7. │ └─rmarkdown::render(main, output_format, ..., clean = clean, envir = envir)
8. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
9. │ └─knitr:::process_file(text, output)
10. │ ├─base::withCallingHandlers(...)
11. │ ├─knitr:::process_group(group)
12. │ └─knitr:::process_group.block(group)
13. │ └─knitr:::call_block(x)
14. │ └─knitr:::block_exec(params)
15. │ ├─knitr:::in_dir(...)
16. │ └─knitr:::evaluate(...)
17. │ └─evaluate::evaluate(...)
18. │ └─evaluate:::evaluate_call(...)
19. │ ├─evaluate:::timing_fn(...)
20. │ ├─base:::handle(...)
21. │ ├─base::withCallingHandlers(...)
22. │ ├─base::withVisible(eval(expr, envir, enclos))
23. │ └─base::eval(expr, envir, enclos)
24. │ └─base::eval(expr, envir, enclos)
25. ├─dplyr::full_join(confirmed, deaths) %>% dplyr::full_join(., recovered)
26. ├─dplyr::full_join(., recovered)
27. ├─dplyr::full_join(confirmed, deaths)
28. └─dplyr:::full_join.data.frame(confirmed, deaths)
29. └─dplyr:::join_mutate(...)
30. └─dplyr:::join_cols(...)
31. └─dplyr:::standardise_join_by(by, x_names = x_names, y_names = y_names)
如何使用 bookdown 将我的代码更改为 运行?
我在进行故障排除时确实遇到了类似的错误。
这是由 运行 每个 command/chunk 单独解决的,直到它完成,我确实遇到间歇性执行问题,有时我会出错,有时 运行 成功,我只是重新 运行 直到完成。
为了更好地帮助我理解,您的 YAML 是什么样的?你究竟是如何构建这本书的?是 gitbook 吗?
我找到解决方案的方法是对簿记有一点了解。我有 2 个文件,index.Rmd
和 01-covid19.Rmd
,index.Rmd
是空的,只有书的 YAML。在 01-covid19.Rmd
我粘贴了你的代码
index.Rmd
---
title: ""
author: ""
date: "`r Sys.Date()`"
output: bookdown::gitbook
site: bookdown::bookdown_site
description: ""
---
# Introduction {-}
01-covid19.Rmd
# Covid19
```{r}
library(tidyverse)
# Importiere Johns Hopkins Github data
confirmedraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_cov id19_confirmed_global.csv")
deathsraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid1 9_deaths_global.csv")
recoveredraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_cov id19_recovered_global.csv")
confirmed <- confirmedraw %>%
gather(key="date", value="confirmed", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>%
summarize(confirmed=sum(confirmed))
deaths <- deathsraw %>%
gather(key="date", value="deaths", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(deaths=sum(deaths))
recovered <- recoveredraw %>%
gather(key="date", value="recovered", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(recovered=sum(recovered))
summary(confirmed)
country <- full_join(confirmed, deaths) %>%
full_join(recovered)
country
```
最终呈现为 Rmarkdown Bookdown 输出,R 代码位于 01
位置。这两个文件必须与其他 Bookdown 依赖项位于同一目录中,还请尝试创建一个新的 R 项目。告诉我,谢谢。
我这里有以下 COVID 19 的 Rmarkdown 代码:
library(tidyverse)
# Importiere Johns Hopkins Github data
confirmedraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")
deathsraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
recoveredraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")
confirmed <- confirmedraw %>%
gather(key="date", value="confirmed", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>%
summarize(confirmed=sum(confirmed))
deaths <- deathsraw %>%
gather(key="date", value="deaths", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(deaths=sum(deaths))
recovered <- recoveredraw %>%
gather(key="date", value="recovered", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(recovered=sum(recovered))
summary(confirmed)
country <- full_join(confirmed, deaths) %>%
full_join(recovered)
这 运行 在 RStudio 预览和 R 控制台本身中都很好。
但是,如果我尝试使用 bookdown 构建我的书,最后一行中的 full_join()
将失败。
我收到错误:
Error: `by` must be supplied when `x` and `y` have no common variables.
ℹ use by = character()` to perform a cross-join.
Backtrace:
█
1. ├─rmarkdown::render_site(output_format = "bookdown::gitbook", encoding = "UTF-8")
2. │ └─generator$render(...)
3. │ ├─xfun::in_dir(...)
4. │ └─bookdown:::render_book_script(output_format, envir, quiet)
5. │ └─bookdown::render_book(...)
6. │ └─bookdown:::render_cur_session(...)
7. │ └─rmarkdown::render(main, output_format, ..., clean = clean, envir = envir)
8. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
9. │ └─knitr:::process_file(text, output)
10. │ ├─base::withCallingHandlers(...)
11. │ ├─knitr:::process_group(group)
12. │ └─knitr:::process_group.block(group)
13. │ └─knitr:::call_block(x)
14. │ └─knitr:::block_exec(params)
15. │ ├─knitr:::in_dir(...)
16. │ └─knitr:::evaluate(...)
17. │ └─evaluate::evaluate(...)
18. │ └─evaluate:::evaluate_call(...)
19. │ ├─evaluate:::timing_fn(...)
20. │ ├─base:::handle(...)
21. │ ├─base::withCallingHandlers(...)
22. │ ├─base::withVisible(eval(expr, envir, enclos))
23. │ └─base::eval(expr, envir, enclos)
24. │ └─base::eval(expr, envir, enclos)
25. ├─dplyr::full_join(confirmed, deaths) %>% dplyr::full_join(., recovered)
26. ├─dplyr::full_join(., recovered)
27. ├─dplyr::full_join(confirmed, deaths)
28. └─dplyr:::full_join.data.frame(confirmed, deaths)
29. └─dplyr:::join_mutate(...)
30. └─dplyr:::join_cols(...)
31. └─dplyr:::standardise_join_by(by, x_names = x_names, y_names = y_names)
如何使用 bookdown 将我的代码更改为 运行?
我在进行故障排除时确实遇到了类似的错误。
这是由 运行 每个 command/chunk 单独解决的,直到它完成,我确实遇到间歇性执行问题,有时我会出错,有时 运行 成功,我只是重新 运行 直到完成。
为了更好地帮助我理解,您的 YAML 是什么样的?你究竟是如何构建这本书的?是 gitbook 吗?
我找到解决方案的方法是对簿记有一点了解。我有 2 个文件,index.Rmd
和 01-covid19.Rmd
,index.Rmd
是空的,只有书的 YAML。在 01-covid19.Rmd
我粘贴了你的代码
index.Rmd
---
title: ""
author: ""
date: "`r Sys.Date()`"
output: bookdown::gitbook
site: bookdown::bookdown_site
description: ""
---
# Introduction {-}
01-covid19.Rmd
# Covid19
```{r}
library(tidyverse)
# Importiere Johns Hopkins Github data
confirmedraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_cov id19_confirmed_global.csv")
deathsraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid1 9_deaths_global.csv")
recoveredraw <- read.csv( "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_cov id19_recovered_global.csv")
confirmed <- confirmedraw %>%
gather(key="date", value="confirmed", -c(Country.Region, Province.State, Lat, Long)) %>% group_by(Country.Region, date) %>%
summarize(confirmed=sum(confirmed))
deaths <- deathsraw %>%
gather(key="date", value="deaths", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(deaths=sum(deaths))
recovered <- recoveredraw %>%
gather(key="date", value="recovered", -c(Country.Region, Province.State, Lat, Long)) %>%
group_by(Country.Region, date) %>%
summarize(recovered=sum(recovered))
summary(confirmed)
country <- full_join(confirmed, deaths) %>%
full_join(recovered)
country
```
最终呈现为 Rmarkdown Bookdown 输出,R 代码位于 01
位置。这两个文件必须与其他 Bookdown 依赖项位于同一目录中,还请尝试创建一个新的 R 项目。告诉我,谢谢。