Rのバージョン4.6.0がリリースされた件

アップデートの内容について見てみます!

R
公開

2026年4月26日

Note

Windows版では、R 4.6.0がリリースされましたが、Linux版、Mac版はまだバイナリが提供されていないようです。本記事もLinux上で書いていますので、実行結果を直接記載できていませんが、Windows上で確認した内容をもとに書いています。

R 4.6.0が4月24日にリリース

昨日(4月24日)、Rの新しいバージョン4.6.0がリリースされました!時差の関係で日本ではほとんど25日にリリースされたようなものですが、早速今回のアップデートの内容について簡単に見ていきたいと思います。

%notin%演算子の追加

個人的にはこれが一番大きい!Rのベースパッケージに、%notin% 演算子が追加されました。これは、%in% の否定バージョンで、ある要素がベクトルに含まれていないかどうかを簡単にチェックできるようになります。

例えば…

x <- c(1, 2, 3)
y <- c(2, 3, 4)
x %notin% y
#> [1]  TRUE FALSE FALSE

詳しく見てみると、Xの要素のうち、1はYに含まれていないためTRUE、2と3はYに含まれているためFALSEとなっています。y %notin% x とすると、4がXに含まれていないためFALSE FALSE TRUEとなります。

これまでは、!(x %in% y) と書いていたのが、より直感的に書けるようになりました!

filter()での応用

dplyrfilter()関数と組み合わせると、特定の条件に合わない行を簡単に抽出できます。

例えば、以下のようなデータフレームがあるとします。

library(dplyr)
df <- data.frame(
  id = 1:5,
  value = c("A", "B", "C", "D", "E")
)

ここでvalueが”B”と”D”であるものは除外したい場合、これまで!(value %in% c("B", "D"))と書いていたところ、

df |> filter(value %notin% c("B", "D"))
#>   id value
#> 1  1     A
#> 2  3     C
#> 3  5     E

として、よりシンプルに書けるようになりました。

小さいデータフレームなのであまり効果を実感できないかもしれませんが、複数の条件付けをする場合などに!を使った否定形が多くなるとコードが読みづらくなってしまうことがあるので、%notin%の導入は非常に有用だと考えています。

summary()関数の改善

一般的によく使われるsummary()関数に関して、文字列列の要約が改善されました。

例えば以下のようなデータフレームがある都市ます。

df <- data.frame(
  prefecture = c("東京都", "大阪府", "東京都", "愛知県", "東京都",
                 "大阪府", "福岡県", "大阪府", "愛知県", "東京都"),
  city       = c("新宿区", "大阪市", "渋谷区", "名古屋市", "港区",
                 "堺市", "福岡市", "大阪市", "豊田市", ""),  # 1件だけ空白
  population = c(346000, 275000, 234000, 232000, 260000,
                 830000, 164000, 270000, 425000, 198000)
)

R 4.5.0の場合、

summary(df)
#>   prefecture            city             population
#>  Length:10          Length:10          Min.   :164000
#>  Class :character   Class :character   1st Qu.:232500
#>  Mode  :character   Mode  :character   Median :265000
#>                                        Mean   :323400
#>                                        3rd Qu.:328250
#>                                        Max.   :830000

となり、文字列の列に関してはほぼ情報量がゼロです。

R 4.6.0では、文字列列の要約が改善され、以下のように表示されるようになりました。

summary(df)
#>      prefecture        city      population
#>  Length   :10   Length   :10   Min.   :164000
#>  N.unique : 4   N.unique : 9   1st Qu.:232500
#>  N.blank  : 0   N.blank  : 1   Median :265000
#>  Min.nchar: 3   Min.nchar: 0   Mean   :323400
#>  Max.nchar: 3   Max.nchar: 4   3rd Qu.:328250
#>                                Max.   :830000

このように、文字列列に対しても、ユニークな値の数や空白の数、最小・最大文字数などの情報が表示されるようになりました。

異常値の有無の確認がやりやすくなったのではないかと感じており、自分の仕事でも出番が来るのではないかなと思ったところです。

その他の変更点

基本的にすぐ役立ちそうだなと思ったのは以上の2点で、あと挙げるとすればplot()関数がパイプで使いやすくなったことでしょうか。

以前はdf |> plot(col2 ~ col1, data = _)のように、データフレームをパイプで渡すときに、data = _と書いてあげる必要がありましたが、R 4.6.0では、df |> plot(col2 ~ col1)のように、data = _を省略して書けるようになりました。

mtcars |> plot(mpg ~ wt)

左下にコマンド、右下にプロットが表示されています

おわりに

今回は、R 4.6.0のリリースに伴う主な変更点について見てきました。

特に、%notin%演算子の追加と、summary()関数の改善は、日常的にRを使う上で非常に便利な機能だと思います。

早速アップデートして使っていきましょう👊

参考

Preview image for What’s new in R 4.6.0? | R-bloggers
What’s new in R 4.6.0? | R-bloggers
R 4.6.0 (“Because it was There”) is set for release on April 24th 2026. Here we summarise some of the more interesting changes that have been introduced. In previous blog posts, we have discussed the new features introduced in R 4.5.0 and earlier versions (see the links at the end of this post). Once R 4.6.0 is released, the full changelog will be available at the r-release ‘NEWS’ page. If you want to keep up to date with developments in base R, have a look at the r-devel ‘NEWS’ page. Data comes in all shapes and sizes. It can often be difficult to know where to start. Whatever your problem, Jumping Rivers can help. ! (values %in% collection) Code should be readable, and easily understood. And although it isn’t a natural language, there’s something off about code that reads like: If not a blog post is readable, I close the browser tab. To check if one (or more) value is in some collection, R has the %in% operator: "a" %in% letters [1] TRUE "a" in LETTERS [1] FALSE This is different from the in keyword, which you use when iterating over a collection: for (x in letters[1:3]) { message(x) } # a # b # c Sometimes you want to know whether a value is absent from a collection. The standard way to do this is to invert results from %in%: ! "a" %in% LETTERS [1] TRUE It’s unambiguous to the R interpreter. But it can be hard to read and understand - on scanning that statement, you might forget that ! acts after the %in%. As such, we often wrap the %in% expression with parentheses to make the code more clear: ! ("a" %in% LETTERS) [1] TRUE For the sake of clarity, many developers have implemented their own absence-checking operator. Writing a custom operator in R uses similar syntax to that used when writing a function: `%NOTIN%` = function(x, y) { ! (x %in% y) } "a" %NOTIN% LETTERS [1] TRUE Were you to write the same code multiple times in the same project, you would write a function. Similarly, if you (or your team) wrote the same function in multiple files or projects, you might add it to a package and import it. So if lots of package developers have implemented the same operator or function, across their CRAN packages, maybe it should be pushed to a higher plane… That is what has happened with the introduction of %notin% in R 4.6.0. An operator that was found across lots of separate packages has been moved up into base R: "a" %notin% LETTERS [1] TRUE "a" %notin% letters [1] FALSE DOI citations If you use R in your publications or your projects, you may need to provide a citation for it. rOpenSci has a blog post about citing R and R packages - why, when and how to do it. For the R project as a whole, there is a simple function citation() that provides the information you need: citation() To cite R in publications use: R Core Team (2026). _R: A Language and Environment for Statistical Computing_. R Foundation for Statistical Computing, Vienna, Austria. doi:10.32614/R.manuals . . A BibTeX entry for LaTeX users is @Manual{, ... } ... In R 4.6.0, a DOI (Digital Object Identifier) has been added to the citation entry to make it easier to reference R in your published work. summary(character_vector, character.method = "factor") str() and summary() are two of the first functions I reach for when exploring a dataset. For a data-frame, these tell me what type of columns are present (str(): chr, num, Date, …); and what is present in each column (summary(): gives the min, max, mean of each numeric column, for example). summary() works with data-structures other than just data-frames. For factors, summary() tells you how many observations of the factor levels were observed: # &#039;species&#039; and &#039;island&#039; are factor columns in `penguins` summary(penguins[1:3]) species island bill_len Adelie :152 Biscoe :168 Min. :32.10 Chinstrap: 68 Dream :124 1st Qu.:39.23 Gentoo :124 Torgersen: 52 Median :44.45 Mean :43.92 3rd Qu.:48.50 Max. :59.60 NA&#039;s :2 For character columns, the output from summary() has been a little obtuse: # R 4.5.0 # &#039;studyName&#039; and &#039;Species&#039; are character columns in `penguins_raw` summary(penguins_raw[1:3]) studyName Sample Number Species Length:344 Min. : 1.00 Length:344 Class :character 1st Qu.: 29.00 Class :character Mode :character Median : 58.00 Mode :character Mean : 63.15 3rd Qu.: 95.25 Max. :152.00 R 4.6.0 adds a neater way to summarise character vectors/columns to summary(): # R 4.6.0 summary(penguins_raw[1:3]) studyName Sample Number Species Length :344 Min. : 1.00 Length :344 N.unique : 3 1st Qu.: 29.00 N.unique : 3 N.blank : 0 Median : 58.00 N.blank : 0 Min.nchar: 7 Mean : 63.15 Min.nchar: 33 Max.nchar: 7 3rd Qu.: 95.25 Max.nchar: 41 Max. :152.00 We can also summarise character vectors/columns as if they were factors: # R 4.6.0 summary(penguins_raw[1:3], character.method = "factor") studyName Sample Number Species PAL0708:110 Min. : 1.00 Adelie Penguin (Pygoscelis adeliae) :152 PAL0809:114 1st Qu.: 29.00 Chinstrap penguin (Pygoscelis antarctica): 68 PAL0910:120 Median : 58.00 Gentoo penguin (Pygoscelis papua) :124 Mean : 63.15 3rd Qu.: 95.25 Max. :152.00 list.files(..., fixed = TRUE) Suppose we have three files in my working directory: abc.Rmd, CONTRIBUTING.md and README.md. If I want to obtain the filenames for the “.md” files from an R script, I can list those files that match a pattern: # R 4.5.0 list.files(pattern = ".md") [1] "abc.Rmd" "CONTRIBUTING.md" "README.md" Hmmm. In the pattern, . actually matches any character. In R 4.5.0, if I want to match the . character explicitly, I can escape it in the pattern. But pattern matching can lead to complicated code in R, because some characters are treated specially by the pattern matcher, and some are treated specially by R’s string parser. To tell R to find files with a literal ‘.md’ in the filename, we escape the . character twice: once for the . (to tell the pattern matcher to match a ., rather than any character), and once to escape the \ (to tell R that the subsequent \ is really a backslash) # R 4.5.0 list.files(pattern = "\.md") [1] "CONTRIBUTING.md" "README.md" R 4.0.x cleaned that up a bit, we can now use ‘raw strings’ in R. Everything between the parentheses in the next pattern is passed directly to the pattern matcher: # R 4.5.0 list.files(pattern = r"(\.md)") Now, in R 4.6.0, we can indicate to list.files() (and the synonym dir()) that our pattern is a fixed string (rather than a regular expression). With this, we don’t need to escape the . character to match the “.md” suffix. list.files(pattern = ".md", fixed = TRUE) [1] "CONTRIBUTING.md" "README.md" Other matters read.dcf() now allows comment lines, which means you can annotate your config files (e.g., for {lintr}). df |> plot(col2 ~ col1) can now be used for base plotting; this is a little neater for exploratory work than df |> plot(col2 ~ col1, data = _) C++20 is now the default C++ standard Trying out R 4.6.0 To take away the pain of installing the latest development version of R, you can use docker. To use the devel version of R, you can use the following commands: docker pull rstudio/r-base:devel-jammy docker run --rm -it rstudio/r-base:devel-jammy Once R 4.6 is the released version of R and the r-docker repository has been updated, you should use the following command to test out R 4.6. docker pull rstudio/r-base:4.6-jammy docker run --rm -it rstudio/r-base:4.6-jammy An alternative way to install multiple versions of R on the same machine is using rig. See also The R 4.x versions have introduced a wealth of interesting changes. These have been summarised in our earlier blog posts: R 4.0.0 R 4.1.0 R 4.2.0 R 4.3.0 R 4.4.0 R 4.5.0 For updates and revisions to this article, see the original post
r-bloggers.com