简体   繁体   English

R降价演示不显示情节

[英]R markdown presentation not displaying plots

I have Rstudio on Windows ( sessionInfo() below) and am trying to build an r presentation using markdown. 我在Windows上有Rstudio sessionInfo()下面是sessionInfo() ),我正在尝试使用markdown构建一个r演示文稿。 When I try to knit HTML or PDF it does not seem to be retaining the folder where plots should be generated from and as a result my presentations are missing plots. 当我尝试编织HTML或PDF时,它似乎没有保留应该生成绘图的文件夹,因此我的演示文稿缺少绘图。 I have confirmed that it does work with a basic html_document though. 我已经确认它确实可以使用基本的html_document。

Does anyone have any ideas on how to resolve? 有没有人对如何解决有任何想法?

MWE (rstudio default with headers for slides) 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.

This generates using the knit html command, but change html_document to ioslides_presentation and it won't pick up the plot 这使用knit html命令生成,但是将html_document更改为ioslides_presentation并且它不会拾取绘图

Rstudio情节问题

SessionInfo SessionInfo

> 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 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 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()

I have found the same issue with RStudio-0.98.983 and R-3.1.1-win. 我发现了与RStudio-0.98.983和R-3.1.1-win相同的问题。 Uninstalling both and reinstalling did NOT solve the issue for me. 卸载并重新安装并没有为我解决问题。 I have tried with RStudio-0.98.994 and it did not work either... 我尝试过使用RStudio-0.98.994并且它也无法正常工作......

Update: This was reported (see link in the comments below) and a solution was found by the RStudio team. 更新:报告了这一点(见下面评论中的链接),RStudio团队找到了解决方案。 It seems it is an issue with the Lua base64 encoder on Windows, which is used in ioslides. 在Windows上使用Lua base64编码器似乎是一个问题,它在ioslides中使用。 The solution is to install the packages httpuv or catools. 解决方案是安装包httpuv或catools。 After restarting RStudio, the issue should be fixed (at least it was for me!). 重新启动RStudio之后,问题应该得到解决(至少对我而言!)。

I had a similar problem with a chart not being displayed. 我有一个类似的问题,图表没有显示。 It turned out that the problem was that the name of the .Rpres file I was using had spaces in it. 原来,问题是我使用的.Rpres文件的名称中有空格。 Once I replaced the spaces with underscores the plot appeared again. 一旦我用下划线替换空格,情节就会再次出现。

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

This is a localised issue - an install on a fresh computer did not have this error. 这是一个本地化问题 - 在新计算机上安装没有此错误。 It could be due to having previous versions of R hanging around - suggest taking the route of completely uninstalling R and Rstudio. 这可能是由于以前版本的R挂了 - 建议采取完全卸载R和Rstudio的路线。

Uninstalling R and Rstudio works. 卸载R和Rstudio工作。

I had the same problem, and a different solution worked for me. 我有同样的问题,一个不同的解决方案对我有用。 - don't save the rmarkdown with any numbers in the document name, - and also don't inlcude the .html in the document name, to the markdown file you wish to save - 不要使用文档名称中的任何数字保存rmarkdown,并且也不要将文档名称中的.html包含在您要保存的markdown文件中

Using just a name without the two above should create one rmd-file and one html-file in your designated folder. 仅使用不带上述两个名称的名称应在指定的文件夹中创建一个rmd文件和一个html文件。 The rmd-file will not include plots, the html-File however should inlcude them in its presentation. rmd文件将不包含图表,但html-File应该在其演示文稿中包含它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM