繁体   English   中英

问题编织 R markdown 到 pdf 与心理 ZEFE90A8E604A7C840E88D03ADB87F6

[英]issues knitting R markdown to pdf with psych package

我遇到的问题是在我将 R-Markdown 文件编织到 pdf(或 word)文档后,我收到以下错误: 在此处输入图像描述

但是,我已经确保在我的 r 中有我的 library(psych) 调用,其中代码块被调用。 The describe() call works just fine when I call it in my.r file in r studio, and when I call it inline in the markdown file, but I still get the error when I knit to pdf.

在此处输入图像描述

在此处输入图像描述

Knitr 代码在.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")

当您单击knit按钮时, knitr在其自己的 R session 中运行代码。 这意味着您在您的环境中拥有的任何东西都不适用于构建您的文档的单独的 session。

特别是,虽然您没有发布整个 Rmarkdown 文件,但问题似乎在于您没有在 .Rmd 文件的任何位置加载psych package。 您应该将它加载到 Rmarkdown 文件中的某个位置,或者在一个单独的块中(如果您不希望它在您的 function 调用之前显示)或在您调用其函数之一的同一块中(在这种情况下, describe() )。


```{r code_2.2}
library(psych)
describe(women_DF)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM