如何解决使用 psych 包将 R markdown 编成 pdf 的问题
我遇到的问题是在将 R-Markdown 文件编织为 pdf(或 word)文档后,出现以下错误:
但是,我已经确保在我的 r 中有我的 library(psych) 调用,其中调用了代码块。当我在 r studio 的 .r 文件中调用它时,describe() 调用工作得很好,当我在 markdown 文件中内联调用它时,但当我编织到 pdf 时仍然出现错误。
## @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 文件,但问题似乎在于您没有在 .Rmd 文件中的任何位置加载 psych
包。您应该将它加载到 Rmarkdown 文件中的某个位置,或者在单独的块中(如果您不希望它在函数调用之前显示)或在调用其函数之一的同一个块中(在这种情况下,{{ 1}}).
describe()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。