我遇到的问题是将R-Markdown文件编织为pdf(或word)文档后,出现以下错误:
但是,我已经确保在我的r中有我的library(psych)调用,在其中调用了代码块。当我在r studio中的.r文件中调用它时,以及在markdown文件中内联调用它时,describe()调用都可以正常工作,但是当我编织到pdf时仍然会收到错误。
.r文件中引用的编织代码。
## @knitr code_2.2
library(psych)
describe(women_DF)
r markdown中的代码块:
## 2.2 Summarize using describe()
* The `summary` function in base R does not show the number of observations and standard deviation of each variable
+ A convenient alternative to `summary` that includes these statistics is `describe` in the `psych` package
* If you have not already done so, install the `psych` package
+ Console: install.packages("psych") or from Packages → Install dialog
* Recall that you must also call `library(psych)` to load the package into memory
* Now use `describe()` to summarize `women_DF`:
```{r code_2.2}
r markdown文件的设置:
---
title: "Module 1 Workshop"
author: "MSBX-5310 (Customer Analyitcs)"
date: "1/14/2021"
output:
pdf_document: default
word_document: default
---
```{r, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
fig.height = 3,
fig.width = 4,
message = FALSE,
comment = NA, error = TRUE)
#uncomment the line below if using an external R script for R chunks
knitr::read_chunk("Workshop1.R")
knitr
当您单击knit
按钮时,将在其自己的R会话中运行代码。这意味着您在环境中拥有的任何内容都无法用于构建文档的单独会话中。
特别是,尽管您没有发布整个Rmarkdown文件,但问题似乎在于您没有psych
在.Rmd文件中的任何位置加载程序包。您应该将其加载到Rmarkdown文件中的某个位置,或者以单独的块(如果您不希望它在函数调用之前显示)加载,也可以在与调用其功能之一相同的块中加载(在本例中为describe()
)。
```{r code_2.2}
library(psych)
describe(women_DF)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句