0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rを閉じるボタンで即座にsaveせず終了する

Posted at

結論

Rを閉じるボタンで即座にsaveせず終了するようにしたければ、.Rprofileに

q <- function (save = "no", status = 0, runLast = TRUE) .Internal(quit(save, status, runLast))

を追加しよう。

注意: 既存の関数の上書きはバグの温床になりかねないので自己責任でお願いします。

Rを終了するには

  • 閉じるボタン
  • q()

のどちらかを実行する。
この時セッションを保存するか聞かれるが、だいたい保存しない(と思う)。
聞かれたくない人は

q(save = "no")

を実行する必要がある。

または、「R を終了させる最短コードがおもしろい」でも紹介されているように、

class(Q)=Q="no";print.no=q

を.Rprofileに記入しておくと、Q一文字で終了できる。

閉じるボタンでも即終了したいんじゃ!

という人は、

関数qの引数既定値をsave = "no"にして上書きすればいい。

標準では
q <- function (save = "default", status = 0, runLast = TRUE) .Internal(quit(save, status, runLast))

となっているので、

q <- function (save = "no", status = 0, runLast = TRUE) .Internal(quit(save, status, runLast))

として、これを.Rprofileに書き込む。

既存の関数の上書きはバグの温床になりかねないので自己責任でお願いします。
最も、他の関数からqが呼び出されることなんて早々ないだろうから大丈夫だろうと思うのですが……。

ちなみに、rm(q)すればいつでも元のq(すなわちbase::q)が使えるようになります。

これは上述のclass(Q)=Q="no";print.no=qとも共存可能で、これでコンソールからでも閉じるボタンからでも即座にRを終了できるようになりました。

やったネ!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?