Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git2r overwrites function from base

The R package git2r seems to overwrite the meaning of the base::merge function. This breaks the below code.

d1 <- c("a", "b")
d2 <- c(1,2)
merge(d1,d2) # This works

# Any call to any git2r function will break the code
git2r::config()

# This does not work anymore.
merge(d1,d2)
base::merge(d1,d2)

The error is:

Error in discover_repository(path) : 
  Error in 'git2r_repository_discover': 'path' must be a character vector of length one with non NA value
In addition: Warning messages:
1: In normalizePath(path) : path[1]="a": No such file or directory
2: In normalizePath(path) : path[2]="b": No such file or directory
> traceback()
5: discover_repository(path)
4: repository(repo)
3: lookup_repository(x)
2: merge.character(d1, d2)
1: base::merge(d1, d2)

What astonishes me is that explicitly specifying base::merge does not solve the issue. It is probably because the git2r::merge function is part of the base namespace, instead of the git2r namespace:

git2r::merge
function (x, y, ...) 
UseMethod("merge")
<bytecode: 0x557184940ee0>
<environment: namespace:base>

How can I either revert the base::merge to the way it was, or avoid git2r overwriting the base::merge altogether ?

I tried calling the git2r::repository inside of a specific environment, I tried copying the base::merge function prior to the git2r::repository call and using it afterwards, I tried to detach the git2r library, but nothing has worked.

like image 579
wohlrajh Avatar asked Oct 28 '25 03:10

wohlrajh


1 Answers

You can fix the issue elegantly by undoing the S3 method registration for merge.character made by the 'git2r' package:

rm('merge.character', envir = .BaseNamespaceEnv$.__S3MethodsTable__.)

That's all that is required to fix the issue. No need to hack around in the namespace of loaded packages.

Alternatively, perform coercion explicitly (this is what merge.default otherwise does):

merge(as.data.frame(d1), d1)
like image 96
Konrad Rudolph Avatar answered Oct 29 '25 20:10

Konrad Rudolph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!