【问题标题】:R markdown presentation not displaying plotsR markdown 演示文稿不显示绘图
【发布时间】:2014-08-21 04:26:36
【问题描述】:

我在 Windows 上有 Rstudio(下面是sessionInfo()),我正在尝试使用 markdown 构建一个 r 演示文稿。当我尝试编写 HTML 或 PDF 时,它似乎没有保留应该从中生成绘图的文件夹,因此我的演示文稿缺少绘图。我已经确认它确实适用于基本的 html_document。

有人对如何解决有任何想法吗?

MWE(rstudio 默认带有幻灯片标题)

---
title: "plottest2"
author: "AN Other"
date: "Monday, June 30, 2014"
output: html_document
---
## Area 1 ##
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

## Area 2 ##
You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

这使用 knit html 命令生成,但是将 html_document 更改为 ioslides_presentation 并且它不会拾取绘图

会话信息

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lattice_0.20-29 ggplot2_1.0.0  

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     evaluate_0.5.5   formatR_0.10     grid_3.1.0       gtable_0.1.2     htmltools_0.2.4  knitr_1.6        labeling_0.2     MASS_7.3-31     
[11] munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.2      reshape2_1.4     rmarkdown_0.2.49 scales_0.2.4     stringr_0.6.2    tools_3.1.0      yaml_2.1.13

C:\Program Files\R\R-3.1.0\library\base\R.Rprofile

### This is the system Rprofile file. It is always run on startup.
### Additional commands can be placed in site or user Rprofile files
#
#  Copyright (C) 1995-2012 The R Core Team
### (see ?Rprofile).

### Notice that it is a bad idea to use this file as a template for
### personal startup files, since things will be executed twice and in
### the wrong environment (user profiles are run in .GlobalEnv).

.GlobalEnv <- globalenv()
attach(NULL, name = "Autoloads")
.AutoloadEnv <- as.environment(2)
assign(".Autoloaded", NULL, envir = .AutoloadEnv)
T <- TRUE
F <- FALSE
R.version <- structure(R.Version(), class = "simple.list")
version <- R.version            # for S compatibility

## for backwards compatibility only
R.version.string <- R.version$version.string

## NOTA BENE: options() for non-base package functionality are in places like
##            --------- ../utils/R/zzz.R

options(keep.source = interactive())
options(warn = 0)
# options(repos = c(CRAN="@CRAN@"))
# options(BIOC = "http://www.bioconductor.org")

options(timeout = 60)
options(encoding = "native.enc")
options(show.error.messages = TRUE)
## keep in sync with PrintDefaults() in  ../../main/print.c :
options(scipen = 0)
options(max.print = 99999)# max. #{entries} in internal printMatrix()
options(add.smooth = TRUE)# currently only used in 'plot.lm'
options(stringsAsFactors = TRUE)
if(!interactive() && is.null(getOption("showErrorCalls")))
    options(showErrorCalls = TRUE)

local({dp <- Sys.getenv("R_DEFAULT_PACKAGES")
       if(identical(dp, "")) # marginally faster to do methods last
           dp <- c("datasets", "utils", "grDevices", "graphics",
                   "stats", "methods")
       else if(identical(dp, "NULL")) dp <- character(0)
       else dp <- strsplit(dp, ",")[[1]]
       dp <- sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) # strip whitespace
       options(defaultPackages = dp)
    })

## Expand R_LIBS_* environment variables.
Sys.setenv(R_LIBS_SITE =
           .expand_R_libs_env_var(Sys.getenv("R_LIBS_SITE")))
Sys.setenv(R_LIBS_USER =
           .expand_R_libs_env_var(Sys.getenv("R_LIBS_USER")))

.First.sys <- function()
{
    for(pkg in getOption("defaultPackages")) {
        res <- require(pkg, quietly = TRUE, warn.conflicts = FALSE,
                       character.only = TRUE)
        if(!res)
            warning(gettextf('package %s in options("defaultPackages") was not found', sQuote(pkg)),
                    call.=FALSE, domain = NA)
    }
}

.OptRequireMethods <- function()
{
      if("methods" %in% getOption("defaultPackages")) {
        res <- require("methods", quietly = TRUE, warn.conflicts = FALSE,
                       character.only = TRUE)
        if(!res)
            warning('package "methods" in options("defaultPackages") was not found', call.=FALSE)
    }
}

if(nzchar(Sys.getenv("R_BATCH"))) {
    .Last.sys <- function()
    {
        cat("> proc.time()\n")
        print(proc.time())
    }
    ## avoid passing on to spawned R processes
    ## A system has been reported without Sys.unsetenv, so try this
    try(Sys.setenv(R_BATCH=""))
}
###-*- R -*-

## this will break if R is on a network share
.Library <- file.path(chartr("\\", "/", R.home()), "library")
.Library.site <- Sys.getenv("R_LIBS_SITE")
.Library.site <- if(!nchar(.Library.site)) file.path(R.home(), "site-library") else unlist(strsplit(.Library.site, ";"))
.Library.site <- .Library.site[file.exists(.Library.site)]

if(!nzchar(Sys.getenv("R_LIBS_USER")))
    Sys.setenv(R_LIBS_USER=
               file.path(Sys.getenv("R_USER"), "R",
                         "win-library",
                         paste(R.version$major,
                               sub("\\..*$", "", R.version$minor),
                               sep=".")
                         ))

invisible(.libPaths(c(unlist(strsplit(Sys.getenv("R_LIBS"), ";")),
                      unlist(strsplit(Sys.getenv("R_LIBS_USER"), ";"))
                      )))

local({
    popath <- Sys.getenv("R_TRANSLATIONS", "")
    if(!nzchar(popath)) {
        paths <- file.path(.libPaths(), "translations", "DESCRIPTION")
        popath <- dirname(paths[file.exists(paths)][1])
    }
    bindtextdomain("R", popath)
    bindtextdomain("R-base", popath)
    bindtextdomain("RGui", popath)
    assign(".popath", popath, .BaseNamespaceEnv)
})

if(nzchar(Sys.getenv("R_PAPERSIZE"))) {
    options(papersize = Sys.getenv("R_PAPERSIZE"))
} else {
    if(grepl("(canada|united.states)", Sys.getlocale("LC_MONETARY"),
             ignore.case = TRUE)) options(papersize = "letter")
    else options(papersize = "a4")
}

options(pager = if(length(grep("--ess", commandArgs()))) "console" else "internal",
        useFancyQuotes = (.Platform$GUI == "Rgui"),
        pdfviewer = Sys.getenv("R_PDFVIEWER", file.path(R.home("bin"), "open.exe")))

if(.Platform$GUI == "Rgui")
    Sys.setenv(GFORTRAN_STDOUT_UNIT = "-1", GFORTRAN_STDERR_UNIT = "-1")

local({
    br <- Sys.getenv("R_BROWSER", NA_character_)
    if(!is.na(br)) options(browser = br)
    tests_startup <- Sys.getenv("R_TESTS")
    if(nzchar(tests_startup)) source(tests_startup)
})

C:\Program Files\R\R-3.1.0\etc\Rprofile.site

# Things you might want to change

# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")

# set the default help type
# options(help_type="text")
  options(help_type="html")

# set a site library
# .Library.site <- file.path(chartr("\\", "/", R.home()), "site-library")

# set a CRAN mirror
# local({r <- getOption("repos")
#       r["CRAN"] <- "http://my.local.cran"
#       options(repos=r)})

# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
#  if (interactive()) 
#    fortunes::fortune()

【问题讨论】:

  • 您的 r 个人资料中有任何内容吗?是否使用图像创建了一个名为 figure 的文件夹?
  • 不,这台机器上没有
  • @rawr - 我可以在更长的示例中看到它正在创建一个文件夹,但在预览窗口出现之前它被删除了。我也尝试创建文件夹结构,但它只会删除它。
  • 回溯到那个 Rprofile q - 3.1 文件夹中有默认值,现在更新 q
  • 仍然无法重现,抱歉。似乎最新的 r studio/knitr 没有创建图形文件夹?我的 Windows 机器上有最新的 rstudio,但在我的 mac(使用较旧的 rstudio)上,我仍然创建了图形文件夹。无论哪种方式,在两台机器上,我都能正确嵌入数字。我想听听是否有人可以评论数字文件夹的事情。你有最新的rstudio吗?

标签: r rstudio r-markdown


【解决方案1】:

我发现 RStudio-0.98.983 和 R-3.1.1-win 存在同样的问题。卸载两者并重新安装并没有解决我的问题。我已经尝试使用 RStudio-0.98.994,但它也没有工作......

更新:已报告此问题(请参阅下面 cmets 中的链接),并且 RStudio 团队找到了解决方案。似乎是 Windows 上的 Lua base64 编码器存在问题,该编码器用于 ioslides。解决方案是安装包 httpuv 或 ctools。重新启动 RStudio 后,问题应该得到解决(至少对我来说是这样!)。

【讨论】:

  • 嗨@Alfonso,可能值得添加一个新Q,提到这个,并添加你自己的sessionInfo()。您是否在重新安装之前卸载了所有内容并删除了以前的 R 文件夹?
  • 感谢您的回答。我不确定我在重新安装之前卸载了包库,我可能会稍后再试。我所做的是将其报告为他们的 github 项目中的一个错误,他们正在调查它。如果他们找到原因和/或修复,我会在这里更新!
  • 他们设法重现了这个问题,所以希望很快能解决。链接:github.com/rstudio/rmarkdown/issues/210
  • 他们找到了解决方案:安装 httpuv 或 ctools 包。相应地编辑了答案文本...
  • 这对我不起作用,但@justinmeyer 发布的解决方案确实:从文件名中删除空格。
【解决方案2】:

我遇到了类似的问题,图表未显示。事实证明,问题在于我使用的 .Rpres 文件的名称中有空格。一旦我用下划线替换了空格,情节又出现了。

使用“Example_File_Name.Rpres”而不是“Example File Name.Rpres”。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,但另一种解决方案对我有用。 - 不要用文档名称中的任何数字保存 rmarkdown, - 并且不要将文档名称中的 .html 包含到您要保存的降价文件中

    仅使用名称而不使用上述两个名称应在您指定的文件夹中创建一个 rmd 文件和一个 html 文件。 rmd 文件不包含绘图,但 html 文件应在其演示文稿中包含它们。

    【讨论】:

    • 这很有趣,如果我必须卸载并重新安装所有 R 和 RStudio,就杀了我
    【解决方案4】:

    这是一个本地化问题 - 在新计算机上安装没有此错误。这可能是由于之前版本的 R 闲置 - 建议采取完全卸载 R 和 Rstudio 的路线。

    卸载 R 和 Rstudio 工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-15
      • 2020-08-09
      • 2019-08-03
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      相关资源
      最近更新 更多