[更新]基于评论。
# 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,我们也没有多行注释或here-字符串,但是在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!"
这是图片...