RStudio中的错误代码诊断报告,当通过源获取功能时

Kon*_*rad 8 environment r scoping rstudio

我在RStudio工作的一个简单的分析,我通过source命令来源一些文件.例如,我有一个简单的分析这个文件:

analysis.R

# Settings ----------------------------------------------------------------

data("mtcars")
source("Generic Functions.R")

# Some work ---------------------------------------------------------------

# Makes no sense
mtcars$mpg <- CleanPostcode(mtcars$mpg)
Run Code Online (Sandbox Code Playgroud)

泛型函数文件有我用它来获得图形,做重复的任务一些简单的功能.例如,使用的CleanPostcode函数看起来像这样:

通用函数.R

#' The file provides a set of generic functions 

# String manipulations ----------------------------------------------------

# Create a clean Postcode for matching
CleanPostcode <- function(MessyPostcode) {
  MessyPostcode <- as.character(MessyPostcode)
  MessyPostcode <- gsub("[[:space:]]", "", MessyPostcode)
  MessyPostcode <- gsub("[[:punct:]]", "", MessyPostcode)
  MessyPostcode <- toupper(MessyPostcode)
  cln_str <- MessyPostcode
  return(cln_str)
}
Run Code Online (Sandbox Code Playgroud)

当我运行第一个文件时,对象在全局环境中可用:

全球环境

文件中还有一些其他功能,但它们与描述的问题无关.

然而,RStudio认为对象在范围内不可用,如代码旁边的黄色三角形所示:

问题

有没有办法让RStudio停止这样做.也许改变source命令的东西?我试过local = TRUE并得到了同样的东西.代码没有问题,我觉得很烦人.


该报告是在RStudio 版本0.99.491上生成的.