如何解决RMarkdown中与维度相关的评估错误

huangapple go评论71阅读模式
英文:

How to solve eval error in RMarkdown referred to dimension

问题

我在RMarkdown中遇到渲染问题。

---
title: "trial"
author: "X"
date: "X"
output:
  word_document:
    toc: yes
    toc_depth: '2'
  html_document:
    fig_caption: yes
    theme: journal
    toc: yes
    toc_depth: 2
  pdf_document:
    fig_caption: yes
    fig_crop: no
    fig_height: 4
    fig_width: 7
    highlight: haddock
    keep_tex: yes
    number_sections: yes
    toc: yes
    toc_depth: 2
header-includes:
- \usepackage{graphicx}
- \usepackage{float}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.path='figure/graphics-', 
                     cache.path='cache/graphics-', 
                     fig.align='center',
                     external=TRUE,
                     echo=TRUE,
                     warning=FALSE,
                     fig.pos='H', ft.tabcolsep=0, ft.latex.float = "none"
                    )

dat_na = data.frame(v1 =ifelse(ttINT_1$HMM$tt$incl == "-", NA, ttINT_1$HMM$tt$incl),
                    v2 = ifelse(ttINT_1$IMM$tt$incl == "-",NA, ttINT_1$IMM$tt$incl), 
                    v3 = ifelse(ttINT_1$LMM$tt$incl == "-",NA, ttINT_1$LMM$tt$incl)
)

它报错了:

如何解决RMarkdown中与维度相关的评估错误

我无法理解它指的是什么。将代码作为代码块单独处理可以解决问题。


【注意】我已保留代码块的格式,只提供翻译,不回答问题。

<details>
<summary>英文:</summary>

I am struggling with this rendering oin RMarkdown

    ---
    title: &quot;trial&quot;
    author: &quot;X&quot;
    date: &quot;X&quot;
    output:
      word_document:
        toc: yes
        toc_depth: &#39;2&#39;
      html_document:
        fig_caption: yes
        theme: journal
        toc: yes
        toc_depth: 2
      pdf_document:
        fig_caption: yes
        fig_crop: no
        fig_height: 4
        fig_width: 7
        highlight: haddock
        keep_tex: yes
        number_sections: yes
        toc: yes
        toc_depth: 2
    header-includes:
    - \usepackage{graphicx}
    - \usepackage{float}
    ---
    
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(fig.path=&#39;figure/graphics-&#39;, 
                     cache.path=&#39;cache/graphics-&#39;, 
                     fig.align=&#39;center&#39;,
                     external=TRUE,
                     echo=TRUE,
                     warning=FALSE,
                     fig.pos=&#39;H&#39;, ft.tabcolsep=0, ft.latex.float = &quot;none&quot;
                    )
        ---
        
    `{r echo=TRUE, message=FALSE, warning=FALSE, paged.print=FALSE}
        
    dat_na = data.frame(v1 =ifelse(ttINT_1$HMM$tt$incl == &quot;-&quot;, NA, ttINT_1$HMM$tt$incl),
                        v2 = ifelse(ttINT_1$IMM$tt$incl == &quot;-&quot;,NA, ttINT_1$IMM$tt$incl), 
                        v3 = ifelse(ttINT_1$LMM$tt$incl == &quot;-&quot;,NA, ttINT_1$LMM$tt$incl)
    )

It turns this error: 

[![enter image description here][1]][1]

I cannot understand what it refers to. It works isolating the code as a chunk 


  [1]: https://i.stack.imgur.com/Hs1fD.png

</details>


# 答案1
**得分**: 1

你的YAML应该在 `---` 之间,你的代码块没有正确使用 ` sign 来创建,应该像这样:

```yaml
---
title: "trial"
author: "X"
date: "X"
output:
  word_document:
    toc: yes
    toc_depth: '2'
  html_document:
    fig_caption: yes
    theme: journal
    toc: yes
    toc_depth: 2
  pdf_document:
    fig_caption: yes
    fig_crop: no
    fig_height: 4
    fig_width: 7
    highlight: haddock
    keep_tex: yes
    number_sections: yes
    toc: yes
    toc_depth: 2
header-includes:
- \usepackage{graphicx}
- \usepackage{float}
---
knitr::opts_chunk$set(fig.path='figure/graphics-', 
                 cache.path='cache/graphics-', 
                 fig.align='center',
                 external=TRUE,
                 echo=TRUE,
                 warning=FALSE,
                 fig.pos='H', ft.tabcolsep=0, ft.latex.float = "none"
                )
dat_na = data.frame(v1 =ifelse(ttINT_1$HMM$tt$incl == "-", NA, ttINT_1$HMM$tt$incl),
                    v2 = ifelse(ttINT_1$IMM$tt$incl == "-",NA, ttINT_1$IMM$tt$incl), 
                    v3 = ifelse(ttINT_1$LMM$tt$incl == "-",NA, ttINT_1$LMM$tt$incl))
英文:

Your yaml should be between --- and your chunks are not rightly created using the ` sign like this:

---
title: &quot;trial&quot;
author: &quot;X&quot;
date: &quot;X&quot;
output:
  word_document:
    toc: yes
    toc_depth: &#39;2&#39;
  html_document:
    fig_caption: yes
    theme: journal
    toc: yes
    toc_depth: 2
  pdf_document:
    fig_caption: yes
    fig_crop: no
    fig_height: 4
    fig_width: 7
    highlight: haddock
    keep_tex: yes
    number_sections: yes
    toc: yes
    toc_depth: 2
header-includes:
- \usepackage{graphicx}
- \usepackage{float}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(fig.path=&#39;figure/graphics-&#39;, 
                 cache.path=&#39;cache/graphics-&#39;, 
                 fig.align=&#39;center&#39;,
                 external=TRUE,
                 echo=TRUE,
                 warning=FALSE,
                 fig.pos=&#39;H&#39;, ft.tabcolsep=0, ft.latex.float = &quot;none&quot;
                )
```

```{r echo=TRUE, message=FALSE, warning=FALSE, paged.print=FALSE}
    
dat_na = data.frame(v1 =ifelse(ttINT_1$HMM$tt$incl == &quot;-&quot;, NA, ttINT_1$HMM$tt$incl),
                    v2 = ifelse(ttINT_1$IMM$tt$incl == &quot;-&quot;,NA, ttINT_1$IMM$tt$incl), 
                    v3 = ifelse(ttINT_1$LMM$tt$incl == &quot;-&quot;,NA, ttINT_1$LMM$tt$incl))
```

huangapple
  • 本文由 发表于 2023年3月7日 02:23:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定