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

7qhs6swi  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(112)

当我尝试编织我的.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

字符串
从本质上讲,它似乎遇到了一个特殊的字符,导致它退出,但它说它遇到的特殊字符并不存在。也就是说,不管Bibr怎么想,都没有错误的%符号。下面是有问题的行。

{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 warnings


正如我所说的,.Rmd文件中的一切都运行得很好,没有错误;我只是在编织时遇到了这个问题。

vuktfyat

vuktfyat1#

如果你使用tidy = TRUE,你不能在一个 * 不完整 * 的表达式后面写注解(请参阅这里的文档)。你必须删除块选项tidy = TRUE,或者将注解移动到一个完整的表达式之前或之后。

相关问题