在全局环境中定义的 R 函数在后续函数中不可见

R Function defined in gloabl environment not visible in subsequent function

我定义了四个函数。当我调用 ls() 时,我已经执行了所有四个出现在全局环境中的代码。 前两个在第三个内部使用,这按预期工作。但是,当我从第四个函数调用第三个函数时,我收到一条错误消息,告诉我 curent_month 不存在。 (我删除了第四个函数中的所有代码,因为失败发生在第一个语句中,因此其余部分不相关。) 我一直明白,在全局环境中定义的任何对象都可用于任何子环境(即函数内部)。 谁能指出我正确的方向?

## Function returns the most recent month having billing revenues
current_month_POSIX <- function(x){
  ## Fetch current month name for use in label below
  current_month_POSIX <- x  %>%
    filter(Year == 2020) %>%
    filter(!is.na(Billing)) %>%
    select(Month) %>%
    unique()%>%
    arrange() %>%
    tail(1) %>%
    unlist() %>%
    as_datetime()
  return(current_month_POSIX)
}

current_month_name <- function(x){
  current_month_name <- x %>%
    filter(Year == 2020) %>%
    filter(!is.na(Billing)) %>%
    select(Month, month_name) %>%
    unique()%>%
    arrange() %>%
    tail(1) %>%
    select(month_name) %>%
    substr(.,1,3)
  return(current_month_name)
}

curent_month <- function(x){
  POSIX <- current_month_POSIX(x)
  name <- current_month_name(x)
  return(list("current_month_name" = name, "current_month_POSIX" = POSIX))
}

### Function to reduce source data to clustered bar chart table
clustered_bar_data <- function(x){
  latest_month <- current_month(x)
}

current_month不存在!您将函数命名为 curent_month.