简体   繁体   English

可以在roxygen2代码块中使用换行符吗?

[英]Possible to use newline inside roxygen2 code block?

I'm wondering if it's possible to insert newlines inside code blocks in roxygen2 when documenting a function? 我想知道在记录函数时是否可以在roxygen2中的代码块中插入换行符?

If I have something inside \\code{} , roxygen2 collapses all newlines into single spaces by default. 如果我在\\code{}有一些内容,默认情况下roxygen2会将所有换行符折叠为单个空格。 I tried inserting \\cr inside to enforce a line break, and I get the desired behaviour, but then I get a WARNING when I "R CMD CHECK". 我尝试插入\\cr来强制执行换行符,然后我得到了所需的行为,但是当我“R CMD CHECK”时我得到一个警告。 Is there a way to do this? 有没有办法做到这一点?

Example: 例:

#' \code{
#'   multiple
#'   lines
#' }

Use \\preformatted instead of \\code . 使用\\preformatted而不是\\code \\code is for inline code (works like `` on SO) and \\preformatted is for verbatim blocks (like indentation on SO). \\code用于内联代码(类似于`` on SO)和\\preformatted用于逐字块(如SO上的缩进)。

#' \preformatted{
#'   multiple
#'   lines
#' }

Note that the initial line break, just after { , will also be part of the code block, so you might want to consider removing it. 请注意,在{之后的初始换行符也将是代码块的一部分,因此您可能需要考虑将其删除。

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

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