[R] error = FALSE causes knit2wp to throw duplicate label error

Nathan Parsons n@th@n@f@p@r@on@ @ending from gm@il@com
Sun Dec 16 20:48:44 CET 2018


Goal: post from R to Wordpress installation on server.

Problem: R keeps returning the error “Error in parse_block(g[-1],
g[1], params.src) : duplicate label 'setup’” if error = FALSE in the
knitr options or in an r chunk. It works fine if error = TRUE. I could
just go through each post each time and remove any returned errors
manually, but I'd like to find a more permanent solution.

I don't have any duplicate labels; is knit2wp somehow introducing a
duplicate label in the .Rmd
-> .md / upload process?

My code:

```{r setup, include=FALSE}
## Set the global chunk options for knitting reports
  knitr::opts_chunk$set(
    echo = TRUE,
    eval = TRUE,
    message = TRUE,
    error = FALSE,
    warning = TRUE,
    highlight = TRUE,
    prompt = FALSE
  )

## Load and activate libraries using 'pacman' package
  if (!require(pacman)) {
    install.packages("pacman", repos = "http://cran.us.r-project.org")
  require(pacman)
  }

  pacman::p_load_gh("duncantl/XMLRPC",
    "duncantl/RWordPress")
  pacman::p_load("knitr")
```

```{r chunk1, echo = FALSE}
## post information
  fileName <- "fancy_post.Rmd"
  postTitle <- "Fancy Post Title"

```

blah blah blah...

```{r chunk2, echo = FALSE}
## Set working directory to correct location
  last_dir <- getwd()
  setwd("~/Sites/posts")

## Tell knitr to create the html code and upload it to your wordpress site
  knit2wp(input = fileName,
    title = postTitle,
    publish = FALSE,
    action = 'newPost')

  setwd(last_dir)
```


Traceback:
Error in parse_block(g[-1], g[1], params.src) : duplicate label 'setup'
26. stop("duplicate label '", label, "'")
25. parse_block(g[-1], g[1], params.src)
24. FUN(X[[i]], ...)
23. lapply(groups, function(g) { block = grepl(chunk.begin, g[1]) if
(!set.preamble && !parent_mode()) { return(if (block) "" else g) ...
22. split_file(lines = text)
21. process_file(text, output)
20. knit(input, encoding = encoding, envir = envir)
19. knit2wp(input = fileName, title = postTitle, publish = FALSE,
action = "newPost")
18. eval(expr, envir, enclos)
17. eval(expr, envir, enclos)
16. withVisible(eval(expr, envir, enclos))
15. withCallingHandlers(withVisible(eval(expr, envir, enclos)),
warning = wHandler, error = eHandler, message = mHandler)
14. handle(ev <- withCallingHandlers(withVisible(eval(expr, envir,
enclos)), warning = wHandler, error = eHandler, message = mHandler))
13. timing_fn(handle(ev <- withCallingHandlers(withVisible(eval(expr,
envir, enclos)), warning = wHandler, error = eHandler, message =
mHandler)))
12. evaluate_call(expr, parsed$src[[i]], envir = envir, enclos =
enclos, debug = debug, last = i == length(out), use_try =
stop_on_error != 2L, keep_warning = keep_warning, keep_message =
keep_message, output_handler = output_handler, include_timing =
include_timing)
11. evaluate::evaluate(...)
10. evaluate(code, envir = env, new_device = FALSE, keep_warning =
!isFALSE(options$warning), keep_message = !isFALSE(options$message),
stop_on_error = if (options$error && options$include) 0L else 2L,
output_handler = knit_handlers(options$render, options))
9. in_dir(input_dir(), evaluate(code, envir = env, new_device = FALSE,
keep_warning = !isFALSE(options$warning), keep_message =
!isFALSE(options$message), stop_on_error = if (options$error &&
options$include) 0L else 2L, output_handler =
knit_handlers(options$render, options)))
8. block_exec(params)
7. call_block(x)
6. process_group.block(group)
5. process_group(group)
4. withCallingHandlers(if (tangle) process_tangle(group) else
process_group(group), error = function(e) { setwd(wd) cat(res, sep =
"\n", file = output %n% "") ...
3. process_file(text, output)
2. knit(input, encoding = encoding, envir = envir)
1. knit2wp(input = fileName, title = postTitle, publish = FALSE,
action = "newPost")



More information about the R-help mailing list