Tom
Tom

Reputation: 5052

Label code chunks in regular Rstudio .r script

An .rmd document in Rstudio is easy to navigate to the various code chunks using the little drop down in the bottom left corner of the script window.

In a regular .r file, functions are listed with a helpful 'f' icon and the function name and commented chunks are also listed with a helpful '#' icon, but with (untitled) next to them.

What do I need to include in my comment so the "(untitled)" will be replaced with a label?

example:

#----------------------------------------------------
# FirstLabel - This is the first chunk of code I want to navigate to.
#----------------------------------------------------

Upvotes: 6

Views: 2872

Answers (3)

Huanyuan Zhang-Zheng
Huanyuan Zhang-Zheng

Reputation: 346

Now there is a workaround, by using package ARTofR or bannerCommenter

For example:

 ARTofR::xxx_title2('FirstLabel')

You will get


##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##                                 FirstLabel                               ----
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are other styles in this package

Upvotes: 1

Bobby
Bobby

Reputation: 1595

#### still works, but now you can also add ---- at the end or click on Code>Insert Section...

# new section ----

The keyboard shortcut on windows is CTRL+SHIFT+R and on Mac: CMD+SHIFT+R

Upvotes: 2

David Arenburg
David Arenburg

Reputation: 92282

Add #### at the end of every comment you want to list

# FirstLabel - This is the first chunk of code I want to navigate to. ####

The nice thing about this is that you can hide everything between these comments using the drop down arrow on the left of the comment

Upvotes: 7

Related Questions