2
2

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.

既存パッケージ内のS4メソッドの書き換え

Posted at

a_bickyさんの記事( http://d.hatena.ne.jp/a_bicky/20130324/1364102923 )見て試してみた。

手元の関数で既存パッケージ内のS4メソッドを書き換える。結構面倒。どんだけ汎用性があるのかわからないけど、この方向で行けそう。
もっと簡単な方法あるのかな?

> updateS4 <- function(fname, def, signature, package) {+   ns <- asNamespace(package)+   environment(def) <- ns+   gen <- getGeneric(fname, ns)+   obj <- methods:::.TableMetaName(fname, gen@package)+   unlockBinding(obj, ns)+   unlockBinding(fname, ns)+   setMethod(fname, signature, def, where = ns)+   lockBinding(fname, ns)+   lockBinding(obj, ns)+ }> > f <- function(x, decreasing = FALSE, ...){+   cat("int64!\n")+   .Call( int64_sort, x, FALSE, decreasing )+ }> > library(int64)> > # function name, definition, signature, package name> updateS4("sort", f, "int64", "int64")> > x <- as.int64(5:1)> sort(x)int64![1] 1 2 3 4 5
2
2
1

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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?