在 Rstudio 中重启 R [英] Restart R within Rstudio

查看:441
本文介绍了在 Rstudio 中重启 R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 system2() 从 R 中调用一个简单的 python 脚本.我读过一些我觉得含糊不清的信息,说如果使用太多"内存,它将无法工作.

I'm trying to call a simple python script from within R using system2(). I've read some information I found vague that said if 'too much' memory is used, it won't work.

如果我加载一个大型数据集并使用其中的一些信息作为参数传递给 system2(),则只有当我在调用 Rstudio 时手动单击重新启动 R"时,它才会起作用.

If I load a large dataset and use some information in it to use as arguments to pass into system2(), it will only work if I manually click "Restart R" in call Rstudio.

我想要的:

df <- read.csv('some_large_file.csv')
###extracting some info called 'args_vec'
for(arg in args_vec){
    system2('python', args)
}

这将无法正常工作.for 循环被简单地忽略了.

This won't work as is. The for loop is simply passed over.

我需要什么:

df <- read.csv('some_large_file.csv')
###extracting some info called 'args_vec'
###something that 'restarts' R
for(arg in args_vec){
    system2('python', args)
}

这个答案没有完全得到我想要的.也就是说,它在 Rstudio 中对我不起作用,它调用system"(在这种情况下它与system2"存在相同的问题).事实上,当我把上面引用的答案放在我的 Rprofile.site 文件中时,它只是立即关闭了 rstudio:

This answer doesn't quite get what I want. Namely, it doesn't work for me within Rstudio and it calls "system" (which presents the same problem as "system2" in this case). In fact, when I put the answer referenced above in my Rprofile.site file, it just immediately closed rstudio:

我将建议作为普通函数尝试(而不是使用makeActiveBinding",但效果不佳.

I tried the suggestion as a normal function (rather than using "makeActiveBinding", and it didn't quite work.

##restart R in r session  -- doesn't work
makeActiveBinding("refresh", function() { system("R --save"); q("no") }, .GlobalEnv)

##nor did this:
refresh <- function() { system("R --save"); q("no") }

我尝试了上面这两个选项的多种变体,但对于一个感觉很简单的问题来说,这已经很长了.关于启动过程,我还有很多不明白的地方,makeActiveBinding"有点神秘.有人能指出我正确的方向吗?

I tried a number of variations of these two options above, but this is getting long for what feels like a simple question. There's a lot I don't yet understand about the startup process and "makeActiveBinding" is a bit mysterious. Can anyone point me in the right direction?

推荐答案

在 Rstudio 中,您可以通过以下方式重新启动 R 会话:

In Rstudio, you can restart the R session by:

command/ctrl + shift + F10 

您也可以使用:

.rs.restartR()

这篇关于在 Rstudio 中重启 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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