を使用してギャザーを持つオペレータ:- そのように、私は、引数としてquosureを取るquosureに<code>-</code>を付加し、<code>gather</code>にあることを渡す関数を書きたいのですが非標準の評価
library(tidyverse)
my_gather <- function(d, not.columns) {
dg <- tidyr::gather(d, key = k, value = v, .dots = -!!!not.columns)
dg
}
de <- my_gather(mtcars, not.columns = quos(mpg, cyl, disp))
> Error in `-`(~mpg, ~cyl, ~disp) : operator needs one or two arguments
この閉鎖全体に-
を追加するのではなく、閉鎖の各要素を-
に追加する必要があるからです。しかし私の仕事では、quos(-mpg, -cyl, -disp)
の形でこの閉鎖を作成するのは簡単ではないでしょう。quos(mpg, cyl, disp)
を変更して-
を追加するにはどうすればよいですか?
私はgather(mtcars, key = k, value = v, -mpg, -cyl, -disp)
と同じである結果を見てみたい、の最初の3行は
mpg cyl disp k v
1 21.0 6 160 hp 110
2 21.0 6 160 hp 110
3 22.8 4 108 hp 93
ありあり同様の質問hereだが、それは未回答で、対処していないようですquo()
ではなくquos()
の問題です。
ができますあなたは結果としてあなたが見たいものをより詳細に記述します この? –
@ 42-:編集を参照してください。 –