如何在R中设置C堆栈的大小? [英] How to set the size of the C stack in R?

查看:465
本文介绍了如何在R中设置C堆栈的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在具有大约三百万个观察值的数据帧上使用R中tidyr包中的spread()函数.它返回以下错误消息:

I'm trying to use the spread() function from the tidyr package in R on a dataframe that has about three million observations. It's returning the following error message:

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

当我运行Cstack_info()时,它会告诉我

When I run Cstack_info(), it tells me

> Cstack_info()
      size    current  direction eval_depth 
   7969177      15272          1          2 

按照

Following the advice in the answer to this question, I've tried increasing the stack size by running ulimit -s 32768 in a terminal window and opening Rstudio from the terminal. When I try this, however, the output of Cstack_info() is unchanged, and when I run my code, I get the same error message. Following another answer to the same earlier question I've tried updating R and Rstudio, also to no avail. What am I doing wrong here?

我正在具有16 GB内存的mac os x 10.12.2上运行R 3.3.

I am running R 3.3 on mac os x 10.12.2 with 16 GB of memory.

推荐答案

我遇到了类似的情况,对于我来说,可以通过设置launchctl限制来增加C Stack的大小.

I encountered a similar situation, and in my case, I could increase the size of C Stack by setting the launchctl limit.

在设置launchctl限制之前:

Before setting the launchctl limit:

> Cstack_info()
      size    current  direction eval_depth 
   7969177      17072          1         2

$ ulimit -s
stack size              (kbytes, -s) 8192

$ sudo launchctl limit
stack       8388608        67104768 

设置launchctl限制:

Setting the launchctl limit:

$ cd /Library/LaunchDaemons/
$ sudo vi limit.stack.plist # create a new plist file to set new stack value

<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>stack</string>
      <string>67104768</string>
      <string>67104768</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

重启后:

> Cstack_info()
      size    current  direction eval_depth 
   63749529      17072          1          2

$ ulimit -s
stack size              (kbytes, -s) 65532

$ sudo launchctl limit
stack       67104768       67104768  


R版本3.5.0
macOS High Sierra 10.13.5


R version 3.5.0
macOS High Sierra 10.13.5

这篇关于如何在R中设置C堆栈的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆