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 3 years have passed since last update.

MacでRStudioを使用するために「.Rprofile」を設定

Posted at

RStudioでパッケージを自動読み込み

M1チップ搭載Macに「RStudio」をインストールしました。
RStudio起動時に、以下を自動実行しパッケージを読み込むために「.Rprofile」を用意しました。

library(stats)
library(tidyverse)
library(ggplot2)
library(GGally)
library(patchwork)
library(lubridate)
library(dplyr)

RStudioの左上パネルで上記を記述します。

image.png

「.Rprofile」というファイル名で保存します。

「.Rprofile」が「.Rprofile.R」になる

ところが、以下のメッセージが出て、

image.png

「.Rprofile.R」という名称で保存されます(RStudioの右下パネル)。

image.png

このままでは設定が読み込まれません。

ターミナルで「.Rprofile.R」を見えるように

ただし、通常「.Rprofile.R」はFinderで表示されません。
そこで、ターミナルで以下を実行し見えるようにします。

% defaults write com.apple.finder AppleShowAllFiles TRUE
% killAll Finder

image.png

ファイル名を「.Rprofile」に変更します。

image.png

Finderで各種ファイルを非表示に戻す場合は以下実行します(削除したくないファイルが見えてしまうので元に戻しました)。

% defaults write com.apple.finder AppleShowAllFiles FALSE
% killall Finder

RStudioに自動取り込み

RStudioを起動すると、以下メッセージが表示され、設定が自動で読み込まれたことがわかります。
「tidyverse」パッケージと重なるパッケージがあったので、「Conflicts」メッセージが出ましたが、とりあえず動作には問題ないので、後で調整することにします。

── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
 ggplot2 3.3.5      purrr   0.3.4
 tibble  3.1.6      dplyr   1.0.8
 tidyr   1.2.0      stringr 1.4.0
 readr   2.1.2      forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
Registered S3 method overwritten by 'GGally':
  method from   
  +.gg   ggplot2

Attaching package: lubridate

The following objects are masked from package:base:

    date, intersect, setdiff, union

右下パネルをみると、「.Rprofile」となっていることが確認できます。

image.png

0
1
2

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?