每次我在RStudio中打开新会话时,都会收到错误消息:

Error: C stack usage  7953936 is too close to the limit

基于对herehere发布的类似问题的建议,我try 在终端中使用ulimit命令,但出现以下错误.

Isabels-MacBook-Pro ~ % ulimit -s
8176

Isabels-MacBook-Pro ~ % R --slave -e 'Cstack_info()["size"]'
Error: C stack usage  7954496 is too close to the limit
Execution halted

然而,当我独自运行ulimit时,我得到:

Isabels-MacBook-Pro ~ % ulimit
unlimited

为了再次判断,我再次try 将其设置为无限:

Isabels-MacBook-Pro ~ % ulimit -s unlimited

但接下来会出现一个新错误:

Isabels-MacBook-Pro ~ % R --slave -e 'Cstack_info()["size"]'
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?
Execution halted

我不知道在这种情况下这意味着什么.Cstack_info()位是否被无限递归卡住了??我很想弄明白这一点,因为它正在妨碍安装一些必要的软件包!

如果有帮助,以下是我的课程信息

R version 4.1.3 (2022-03-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1

以及.Rprofile

# REMEMBER to restart R after you modify and save this file!

# First, execute the global .Rprofile if it exists. You may configure blogdown
# options there, too, so they apply to any blogdown projects. Feel free to
# ignore this part if it sounds too complicated to you.
if (file.exists("~/.Rprofile")) {
  base::sys.source("~/.Rprofile", envir = environment())
}

# Now set options to customize the behavior of blogdown for this project. Below
# are a few sample options; for more options, see
# https://bookdown.org/yihui/blogdown/global-options.html
options(
  # to automatically serve the site on RStudio startup, set this option to TRUE
  blogdown.serve_site.startup = FALSE,
  # to disable knitting Rmd files on save, set this option to FALSE
  blogdown.knit.on_save = TRUE,
  # build .Rmd to .html (via Pandoc); to build to Markdown, set this option to 'm$
  blogdown.method = 'html'
)

# fix Hugo version
options(blogdown.hugo.version = "0.82.0")

以下是/Library/Frameworks/R.framework/Resources/Library/base/R/Rprofile中的内容

### This is the system Rprofile file. It is always run on startup.
### Additional commands can be placed in site or user Rprofile files
### (see ?Rprofile).

### Copyright (C) 1995-2020 The R Core Team

### Notice that it is a bad idea to use this file as a template for
### personal startup files, since things will be executed twice and in
### the wrong environment (user profiles are run in .GlobalEnv).

.GlobalEnv <- globalenv()
attach(NULL, name = "Autoloads")
.AutoloadEnv <- as.environment(2)
assign(".Autoloaded", NULL, envir = .AutoloadEnv)
T <- TRUE
F <- FALSE
R.version <- structure(R.Version(), class = "simple.list")
version <- R.version            # for S compatibility

## for backwards compatibility only
R.version.string <- R.version$version.string

## NOTA BENE: options() for non-base package functionality are in places like
##            --------- ../utils/R/zzz.R

options(keep.source = interactive())
options(warn = 0)
# options(repos = c(CRAN="@CRAN@"))
# options(BIOC = "http://www.bioconductor.org")

## setting from an env variable added in 4.0.2
local({to <- as.integer(Sys.getenv("R_DEFAULT_INTERNET_TIMEOUT", 60))
    if (is.na(to) || to <= 0) to <- 60L
    options(timeout = to)
})
options(encoding = "native.enc")
options(show.error.messages = TRUE)
## keep in sync with PrintDefaults() in  ../../main/print.c :
options(show.error.messages = TRUE)
## keep in sync with PrintDefaults() in  ../../main/print.c :
options(scipen = 0)
options(max.print = 99999)# max. #{entries} in internal printMatrix()
options(add.smooth = TRUE)# currently only used in 'plot.lm'

if(isFALSE(as.logical(Sys.getenv("_R_OPTIONS_STRINGS_AS_FACTORS_",
                                 "FALSE")))) {
    options(stringsAsFactors = FALSE)
} else {
    options(stringsAsFactors = TRUE)
}

if(!interactive() && is.null(getOption("showErrorCalls")))
    options(showErrorCalls = TRUE)

local({dp <- Sys.getenv("R_DEFAULT_PACKAGES")
       if(identical(dp, "")) ## it fact methods is done first
           dp <- c("datasets", "utils", "grDevices", "graphics",
                   "stats", "methods")
       else if(identical(dp, "NULL")) dp <- character(0)
       else dp <- strsplit(dp, ",")[[1]]
       dp <- sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) # strip whitespace
       options(defaultPackages = dp)
    })

## Expand R_LIBS_* environment variables.
Sys.setenv(R_LIBS_SITE =
           .expand_R_libs_env_var(Sys.getenv("R_LIBS_SITE")))
Sys.setenv(R_LIBS_USER =
           .expand_R_libs_env_var(Sys.getenv("R_LIBS_USER")))

local({
    if(nzchar(tl <- Sys.getenv("R_SESSION_TIME_LIMIT_CPU")))
        setSessionTimeLimit(cpu = tl)
    if(nzchar(tl <- Sys.getenv("R_SESSION_TIME_LIMIT_ELAPSED")))
        setSessionTimeLimit(elapsed = tl)
})

        setSessionTimeLimit(elapsed = tl)
})

.First.sys <- function()
{
    for(pkg in getOption("defaultPackages")) {
        res <- require(pkg, quietly = TRUE, warn.conflicts = FALSE,
                       character.only = TRUE)
        if(!res)
            warning(gettextf('package %s in options("defaultPackages") was not found', sQuote(pkg)$
                    call. = FALSE, domain = NA)
    }
}

## called at C level in the startup process prior to .First.sys
.OptRequireMethods <- function()
{
    pkg <- "methods" # done this way to avoid R CMD check warning
    if(pkg %in% getOption("defaultPackages"))
        if(!require(pkg, quietly = TRUE, warn.conflicts = FALSE,
                    character.only = TRUE))
            warning('package "methods" in options("defaultPackages") was not found',
                    call. = FALSE)
}

if(nzchar(Sys.getenv("R_BATCH"))) {
    .Last.sys <- function()
    {
        cat("> proc.time()\n")
        print(proc.time())
    }
    ## avoid passing on to spawned R processes
    ## A system has been reported without Sys.unsetenv, so try this
    try(Sys.setenv(R_BATCH=""))
}

local({
    if(nzchar(rv <- Sys.getenv("_R_RNG_VERSION_")))

local({
    if(nzchar(rv <- Sys.getenv("_R_RNG_VERSION_")))
        suppressWarnings(RNGversion(rv))
})

.sys.timezone <- NA_character_
.First <- NULL
.Last <- NULL
###-*- R -*- Unix Specific ----

.Library <- file.path(R.home(), "library")
.Library.site <- Sys.getenv("R_LIBS_SITE")
.Library.site <- if(!nzchar(.Library.site)) file.path(R.home(), "site-library") else unlist(strspl$
.Library.site <- .Library.site[file.exists(.Library.site)]

invisible(.libPaths(c(unlist(strsplit(Sys.getenv("R_LIBS"), ":")),
                      unlist(strsplit(Sys.getenv("R_LIBS_USER"), ":")
                      ))))
local({
    popath <- Sys.getenv("R_TRANSLATIONS", "")
    if(!nzchar(popath)) {
        paths <- file.path(.libPaths(), "translations", "DESCRIPTION")
        popath <- dirname(paths[file.exists(paths)][1])
    }
    bindtextdomain("R", popath)
    bindtextdomain("R-base", popath)
    assign(".popath", popath, .BaseNamespaceEnv)
})
local({
## we distinguish between R_PAPERSIZE as set by the user and by configure
papersize <- Sys.getenv("R_PAPERSIZE_USER")
if(!nchar(papersize)) {
    lcpaper <- Sys.getlocale("LC_PAPER") # might be null: OK as nchar is 0
    papersize <- if(nchar(lcpaper))
        if(length(grep("(_US|_CA)", lcpaper))) "letter" else "a4"
    else Sys.getenv("R_PAPERSIZE")
}
options(papersize = papersize,

}
options(papersize = papersize,
        printcmd = Sys.getenv("R_PRINTCMD"),
        dvipscmd = Sys.getenv("DVIPS", "dvips"),
        texi2dvi = Sys.getenv("R_TEXI2DVICMD"),
        browser = Sys.getenv("R_BROWSER"),
        pager = file.path(R.home(), "bin", "pager"),
        pdfviewer = Sys.getenv("R_PDFVIEWER"),
        useFancyQuotes = TRUE)
})

## non standard settings for the R.app GUI of the macOS port
if(.Platform$GUI == "AQUA") {
    ## this is set to let RAqua use both X11 device and X11/TclTk
    if (Sys.getenv("DISPLAY") == "")
        Sys.setenv("DISPLAY" = ":0")

    ## this is to allow gfortran compiler to work
    Sys.setenv("PATH" = paste(Sys.getenv("PATH"),":/usr/local/bin",sep = ""))
}## end "Aqua"

## de-dupe the environment on macOS (bug in Yosemite which affects things like PATH)
if (grepl("^darwin", R.version$os)) local({
    ## we have to de-dupe one at a time and re-check since the bug affects how
    ## environment modifications propagate
    while(length(dupes <- names(Sys.getenv())[table(names(Sys.getenv())) > 1])) {
        env <- dupes[1]
        value <- Sys.getenv(env)
        Sys.unsetenv(env)             ## removes the dupes, good
        .Internal(Sys.setenv(env, value)) ## wrapper requries named vector, a pain, hence internal
    }
})

local({
    tests_startup <- Sys.getenv("R_TESTS")
    if(nzchar(tests_startup)) source(tests_startup)
})

有没有什么明显的东西可能会导致这个问题?

推荐答案

由于某些原因,用户.Rprofile文件正在递归加载自身:

if (file.exists("~/.Rprofile")) {
  base::sys.source("~/.Rprofile", envir = environment())
}

从您的 comments 来看,这些行似乎是inside 100(~扩展到用户主目录,即在您的情况下是/Users/mycomputer,假设mycomputer是您的用户名).

删除这些行(或注释掉),它们不属于这里.实际上,该文件看起来像是特定于项目的.Rprofile配置的模板.这在项目目录中是有意义的,但在全配置文件用户.Rprofile中是没有意义的.

logic for these files个数字如下:

  • 如果当前目录中有.Rprofile个文件,R将try 加载该文件.
  • 否则,如果环境变量R_PROFILE_USER被设置为文件的路径,Rtry 加载该文件.
  • 否则,如果文件~/.Rprofile存在,R将try 加载该文件.

现在,这意味着如果存在特定于项目的(=当前工作目录中).Rprofile~/.Rprofile将自动加载.这是不幸的,因此许多项目在其特定于项目的.Rprofile文件中添加了与上述类似的行,从而导致用户范围的~/.Rprofile也被加载.然而,上面的实现忽略了R_PROFILE_USER环境变量.因此,更好的实施方案如下所示:

rprofile = Sys.getenv('R_PROFILE_USER', '~/.Rprofile')
if (file.exists(rprofile)) {
  base::sys.source(rprofile, envir = environment())
}
rm(rprofile)

R相关问答推荐

在R中查找每个组不同时间段的总天数

如何对数据集进行逆向工程?

用derrr在R中查找组间的重复项

如何在R中合并和合并多个rabrame?

当月份额减go 当月份额

在R中使用数据集名称

如何优化向量的以下条件赋值?

如何将使用rhandsontable呈现的表值格式化为百分比,同时保留并显示完整的小数精度?

汇总数据的Sheffe检验的P值(平均值和标准差)

基于Key->Value数据帧的基因子集相关性提取

在另一个包中设置断点&S R函数

从多层嵌套列表构建Tibble?

R -使用矩阵reshape 列表

如何创建累加到现有列累计和的新列?

通过匹配另一个表(查找表)中的列值来填充数据表,并在另一个变量上进行内插

如何在R中使用因子行求和?

如何修复geom_rect中的层错误?

如何从矩阵绘制环弦图

向数据添加标签

使用grepl过滤特定列范围内的列名