Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Global env:
- square <- function(x) {
- x ^ 2
- }
- const <- 2
- nonassigned <- function(p) {
- t <- p * 2 # t assigned but not used
- p * 2
- }
- wronguse <- function(x) {
- return(square(...))
- }
- ## Check global environment:
- ls()
- ## [1] "const" "nonassigned" "square" "wronguse"
- ## findLocals
- ## ----------
- codetools::findLocals(quote(q<-1))
- ## [1] "q"
- codetools::findLocals({
- quote({
- square <- function(x) {
- x ^ 2
- }
- const <- 2
- })
- })
- ## [1] "const" "square"
- ## checkUsage
- ## ----------
- codetools::checkUsage(
- quote({
- square <- function(x) {
- x ^ 2
- }
- })
- )
- ## <anonymous>: Error while checking: only works for closures
- codetools::checkUsage(square)
- ## <anonymous>: Error while checking: object 'square' not found
- ## checkUsageEnv
- ## -------------
- codetools::checkUsageEnv(globalenv())
- ## nonassigned: local variable 't' assigned but may not be used (<text>:8)
- ## wronguse: ... may be used in an incorrect context: 'square(...)' (<text>:13)
- ## collectUsage
- ## ------------
- codetools::collectUsage(square)
- ## NULL
- codetools::collectUsage(wronguse)
- ## Warning: <anonymous>: ... may be used in an incorrect context: 'square(...)' (<text>:13)
- ## NULL
- ## findGlobals
- ## -----------
- codetools::findGlobals(square)
- ## [1] "{" "^"
- codetools::findGlobals(nonassigned)
- ## [1] "{" "*" "<-"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement