fanyi icon indicating copy to clipboard operation
fanyi copied to clipboard

translate_ggplot后的对象在print或save时报错 Error in while (nchar(st) > width) { : missing value where TRUE/FALSE needed"

Open shiyw opened this issue 1 year ago • 0 comments

附件

plots.zip

  • plot为翻译前的对象
  • plot2为翻译后的对象

错误提示

下面的各行均会报错

plot2
ggsave(plot2)
ggplot_build(plot2)$layout$panel_params[[1]]$y$get_labels()

错误提示为

Error in while (nchar(st) > width) { : 
  missing value where TRUE/FALSE needed

其他可供参考的定位信息:

Caused by error in `while (nchar(st) > width) {
    if (length(grep(pattern = " ", x = st, perl = use_perl())) == 0) break
    y <- gregexpr(pattern = " ", text = st, perl = use_perl())
    y <- y[[1]]
    n <- nchar(st)
    y <- c(y, n)
    idx <- which(y < width)
    if (length(idx) == 0) idx <- 1
    words[[i]] <- substring(st, 1, y[idx[length(idx)]] - 1)
    st <- substring(st, y[idx[length(idx)]] + 1, n)
    i <- i + 1
  }`:
! missing value where TRUE/FALSE needed
---
BACKTRACE
10 lines omitted
 11.               └─ggplot2::ggsave(path, plot, width = width, height = height, limitsize = FALSE) at R/general_utils/ggsave_sizes.R:38:3
 12.                 ├─grid::grid.draw(plot)
 13.                 └─ggplot2:::grid.draw.ggplot(plot)
 14.                   ├─base::print(x)
 15.                   └─enrichplot:::print.enrichplotDot(x)
 16.                     ├─base::print(p)
 17.                     └─ggplot2:::print.ggplot(p)
 18.                       ├─ggplot2::ggplot_gtable(data)
 19.                       └─ggplot2:::ggplot_gtable.ggplot_built(data)
 20.                         └─layout$setup_panel_guides(plot$guides, plot$layers, plot$mapping)
 21.                           └─ggplot2 (local) setup_panel_guides(..., self = self)
 22.                             └─base::lapply(...)
 23.                               └─ggplot2 (local) FUN(X[[i]], ...)
 24.                                 └─ggplot2 (local) train_panel_guides(..., self = self)
 25.                                   └─base::lapply(...)
 26.                                     └─ggplot2 (local) FUN(X[[i]], ...)
 27.                                       ├─ggplot2::guide_train(guide, panel_params[[aesthetic]])
 28.                                       └─ggplot2:::guide_train.axis(guide, panel_params[[aesthetic]])
 29.                                         └─scale$get_labels(breaks)
 30.                                           └─ggplot2 (local) get_labels(..., self = self)
 31.                                             └─self$scale$get_labels(breaks)
 32.                                               └─ggplot2 (local) get_labels(..., self = self)
 33.                                                 └─self$labels(breaks)
 34.                                                   └─enrichplot (local) labels(...)
 35.                                                     └─yulab.utils::str_wrap(str, n)
 36.                                                       └─base::vapply(...)
 37.                                                         └─yulab.utils (local) FUN(X[[i]], ...)

环境

  • Ubuntu 22.04
  • R 4.3.3
  • fanyi 0.0.7
  • clusterProfiler 4.10.1

可能原因

可能是因为breaks中有NA

z = ggplot_build(plot2)$layout$panel_params[[1]]$y
z$get_breaks()
[1-34] 略去                                    
[35] "帕金森病 (Parkinson disease)"                                                    NA                                                                               
attr(,"pos")
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

很奇怪,翻译前的图片的break只有35个,不知道为什么翻译之后变成了36个(在最后多了一个NA)

shiyw avatar Dec 06 '24 18:12 shiyw