Search code examples
rnaming-conventionsr-markdownunused-variables

Convention for cell-local variables in R markdown


I often have variables in cells that I do not need again. Say a loop index or just an intermediate result. These build up in the list of variables in RStudio, and it does not make it easier to work with.

Therefore I would like to mark those “cell local” variables such that they are not used in other cells. I am using underscores instead of dots to separate words in identifiers, sticking with Hadley Wickam's guideline.

One convention that I have seen is prefixing with a dot. Does that make sense in this case? Or rather an underscore, like in Python?


Solution

  • I assume you mean "chunk local." There is nothing automatic I know of, but if you a convention like a leading ., you can periodically run something like

     rm(grep("^.", ls(), value=TRUE))
    

    in a chunk