R Markdown ggplot 编织错误 - 不存在的意外特殊字符

问题描述 投票:0回答:1

当我尝试编织 .Rmd 文件时遇到错误。代码本身在文件内运行良好;仅当我尝试编织时才会出现错误。

Quitting from lines 103-118 [unnamed-chunk-4] (Lab-14.Rmd)
Warning messages:
1: In eng_r(options) :
  Failed to tidy R code in chunk 'unnamed-chunk-2'. Reason:
Error in base::parse(text = code, keep.source = keep.source) : 
  <text>:4:21: unexpected SPECIAL
3: geography = 'tract' ,
4: county = counties , %
                       ^

2: In eng_r(options) :
  Failed to tidy R code in chunk 'unnamed-chunk-3'. Reason:
Error in base::parse(text = code, keep.source = keep.source) : 
  <text>:5:63: unexpected SPECIAL
4: theme_minimal ( ) +
5: scale_fill_viridis_c ( option = "magma" , direction = - 1 ) + %
                                                                 ^

Execution halted

本质上,它似乎在某种程度上遇到了一个特殊字符,导致它退出,但它所说的遇到的特殊字符并不存在。也就是说,无论 knitr 怎样想,都不存在错误的

%
符号。这是有问题的行。

```{r tidy=TRUE, tidy.opts=list(width.cutoff=68)}
all_2014 <- ggplot(bunc.SNAP_geq_Pov, aes(fill = percent_geq_pov)) + 
  geom_sf(color = "black", size = .5) +  
  theme_minimal() +
  scale_fill_viridis_c(option = "magma", direction = -1) + ggtitle("2014") +
  theme(plot.title = element_text(size = 8, face = "bold")) +
  # facet_wrap(~county) + 
  # Here, it will place them together to form the overall area but I can't delineate between county boundaries since this is on the tract level
  theme(
    panel.grid.major.x = element_blank(),  
    panel.grid.minor.x = element_blank(), 
    panel.grid.major.y = element_line(),   
    panel.grid.minor.y = element_blank(),  
    axis.text = element_text(angle = 30, vjust = 1, hjust = 0.8, size = 5),
    legend.position = "none" 
  )
```

这是我正在使用的库。

library(tidyverse)
library(dplyr)
library(pander)
library(ggplot2)
library(GGally)
library(sf)
library(mapview)
library(tigris)
library(tidycensus)
library(tmaptools)
library(patchwork)
library(viridis)
options(tigris_use_cache = TRUE) # trying to silence those god awful warnings

正如我所说,一切运行良好,.Rmd 文件内有 0 个错误;我只在编织时遇到这个问题。

r ggplot2 r-markdown knitr tidycensus
1个回答
0
投票

如果您使用

tidy = TRUE
,则无法在 incomplete 表达式之后编写注释(请参阅此处的文档)。您必须删除块选项
tidy = TRUE
,或者将注释移至完整表达式之前或之后。

© www.soinside.com 2019 - 2024. All rights reserved.