在** rticles **包的`jss_article()`中格式化问题

时间:2019-06-03 20:22:41

标签: r r-markdown knitr

我正在基于R Studio中的JSS模板来准备自己的稿件。间接地,我使用的是 rticles 包中的jss_article()。现在,按照期刊提交的说明,我通过使用精确的LaTex命令准备了我的文章。

但是,我遇到了以下格式问题。

[]我希望jss_article()执行r print(x)之类的内联代码命令。保持不变,它无法像Rmarkdown error #385 (along with others)一样进行编译。解决方案完成后,我在上面加上了美元符号。但是,内联代码未执行,而是打印到屏幕上。在JSS格式中,内联命令是否未在rticles::jss_article()中执行? []通常,我想使用内联代码从列表中提取元素,例如r print(x$B)。由于“ $”是LaTex符号,因此我需要使用“ \”。执行$ r print(x\$B) $会导致  enter image description here

[]长名称像# Example 4: Interval-Censored data with univariate Bayesian multivariate imputation .一样在页面外流失,在JSS模板中似乎忽略了 knitr tidytidy.opts选项的使用。

[] jss_article()中似乎不支持knitr :: kable()功能。您可以推荐一个函数来构造值得发布的表(类似于kable()的输出)吗?

RStudio模板经过编辑以反映以下问题:

---
documentclass: jss
author:
  - name: FirstName LastName
    affiliation: University/Company
    address: >
      First line
      Second line
    email: \email{name@company.com}
    url: http://rstudio.com
  - name: Second Author
    affiliation: Affiliation
title:
  formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
  # If you use tex in the formatted title, also supply version without
  plain:     "A Capitalized Title: Something about a Package foo"
  # For running headers, if needed
  short:     "\\pkg{foo}: A Capitalized Title"
abstract: >
  The abstract of the article.
keywords:
  # at least one keyword must be supplied
  formatted: [keywords, not capitalized, "\\proglang{Java}"]
  plain:     [keywords, not capitalized, Java]
preamble: >
  \usepackage{amsmath}
output: rticles::jss_article
---

#Issues here
[ ] It seems that inline R code does not run. As mentioned in rmardown error#385, I need to put dollar signs around it.  <!--  $ r print(x)$  --> Is this the case.
[ ] If I want to use inline R code while picking an element from the list I'll need to use the "$" sign. However, it is a special character; do I hit escape?
[ ] Long names run off the page, like `# Example 4: Interval-Censored data with univariate Bayesian multivariate imputation .`
[ ] `knitr::kable()` does not seem to be supported. Can you recommend a function that provides publication-worthy tables using `jss_article()`? 

# Example 4: Interval-Censored data with univariate Bayesian multivariate imputation  

This template demonstrates some of the basic latex you'll need to know to create a JSS article.

```{r echo = FALSE}
knitr::opts_chunk$set(tidy = "styler",
                      tidy.opts = list(blank = FALSE, width.cutoff = 40)
)
                      # options for tidy to remove blank lines [blank = FALSE] and set the approximate line width to be 80.
```

# R code
Can be inserted in regular R markdown blocks.

```{r}
x <- as.list(1:10)
names(x) <- LETTERS[1:10]
x$A
```

blah blah blah $`r print(x)`.$ I want 2 here.
and <!--$ r print(x). $  I want to print element B of x, or 2. -->

```{r}
l <- list(x = x, a = letters)

fit <- lm(y~x, data = data.frame(x = 1:10, y = rnorm(10)))

knitr::kable( summary(fit)$coefficients ) 
#              label = "bootWQS", 
 #             digits = 3, caption = "WQS estimates using bootstrap multiple imputation. Summary of statistics after performing WQS regression across two datasets. " ) 
```

# Computational Details
Using Github versions of **rticles** package had the same result.

```{r, echo =FALSE}
xfun::session_info('rticles')
```

Knitting the document yields the following output.

enter image description here

1 个答案:

答案 0 :(得分:0)

文章的作者

Xiangyun Huang通过以下方式解决了这些问题:

有关这些问题的其他说明:

  • 要执行内联R代码,请不要使用美元符号,而应使用常规r ...语法。
  • 主要标头#的长标题仍在页面之外。该行为由日记帐文档类(jss.cls)定义。最简单的解决方案:避免使用太长的第一级标头。
  • 由于 booktabs 软件包,长时间的辅助标头##仍然在线并且不会在页面外运行。
  • 要创建漂亮的表,仍然使用kable(),但添加formatbooktabs参数:
knitr::kable(summary(fit)$coefficients, digits = 3, 
label = "demo-table" caption = " A CAPTION HERE ", 
format = "latex", booktabs = TRUE
)

See the cross-post for more information.

documentclass: jss
author:
 - name: FirstName LastName
    affiliation: University/Company
    address: >
      First line
      Second line
    email: \email{name@company.com}
    url: http://rstudio.com
 - name: Second Author
    affiliation: Affiliation
title:
  formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
  # If you use tex in the formatted title, also supply version without
  plain:     "A Capitalized Title: Something about a Package foo"
  # For running headers, if needed
  short:     "\\pkg{foo}: A Capitalized Title"
abstract: >
  The abstract of the article.
keywords:
  # at least one keyword must be supplied
  formatted: [keywords, not capitalized, "\\proglang{Java}"]
  plain:     [keywords, not capitalized, Java]
preamble: >
  \usepackage{amsmath}
  \usepackage{booktabs} 
output: 
  bookdown::pdf_book: 
    base_format: rticles::jss_article
---

```
knitr::opts_chunk$set(
  tidy = "formatR",
  tidy.opts = list(blank = FALSE, width.cutoff = 40)
)
```

## Example 4: Interval-Censored data with univariate Bayesian multivariate imputation

1. Executing R commands. Dollar signs are not needed. 
blah blah blah `r x$B`. 

1. A pretty table

```r 
fit <- lm(y ~ x, data = data.frame(x = 1:10, y = rnorm(10)))
knitr::kable(summary(fit)$coefficients,
             label = "demo-table",
  digits = 3, caption = " A CAPTION HERE ", format = "latex", booktabs = TRUE
)
```
demo table \@ref(tab:demo-table)