[更新] 基于评论。
# An empty function for Comments
Comment <- function(`@Comments`) {invisible()}
#### Comments ####
Comment( `
# Put anything in here except back-ticks.
api_idea <- function() {
return TRUE
}
# Just to show api_idea isn't really there...
print( api_idea )
`)
####
#### Code. ####
foo <- function() {
print( "The above did not evaluate!")
}
foo()
[原答案]
这是另一种方式...查看底部的图片。将代码块剪切并粘贴到 RStudio 中。
使使用 IDE更有效的多行注释是“好事”,大多数 IDE 或简单的编辑器在简单的注释块内没有突出显示文本;尽管有些作者花时间确保在此处字符串中进行解析。使用 R,我们也没有多行注释或此处的字符串,但是在 RStudio 中使用不可见的表达式可以提供所有这些好处。
只要在希望用于多行注释、此处字符串或未执行的注释块的部分中没有任何反引号,那么这可能是值得的。
#### Intro Notes & Comments ####
invisible( expression( `
{ <= put the brace here to reset the auto indenting...
Base <- function()
{ <^~~~~~~~~~~~~~~~ Use the function as a header and nesting marker for the comments
that show up in the jump-menu.
--->8---
}
External <- function()
{
If we used a function similar to:
api_idea <- function() {
some_api_example <- function( nested ) {
stopifnot( some required check here )
}
print("Cut and paste this into RStudio to see the code-chunk quick-jump structure.")
return converted object
}
#### Code. ####
^~~~~~~~~~~~~~~~~~~~~~~~~~ <= Notice that this comment section isnt in the jump menu!
Putting an apostrophe in isn't causes RStudio to parse as text
and needs to be matched prior to nested structure working again.
api_idea2 <- function() {
} # That isn't in the jump-menu, but the one below is...
api_idea3 <- function() {
}
}
# Just to show api_idea isn't really there...
print( api_idea )
}`) )
####
#### Code. ####
foo <- function() {
print( "The above did not evaluate and cause an error!")
}
foo()
## [1] "The above did not evaluate and cause an error!"
这是图片...