Skip to content

"Error: fn must be an R function, not a primitive function" after library call #48

@moodymudskipper

Description

@moodymudskipper

This happens when attaching one of my packages :

library(conflicted)
library(inops)
#> Error: `fn` must be an R function, not a primitive function

The package can be attached without problem if conflicted is not attached.

library(inops)
#> 
#> Attaching package: 'inops'
#> The following object is masked from 'package:base':
#> 
#>     <<-

It appears to come from the fact that the package overrides a primitive (namely <<-).

library(conflicted) triggers conflicted:::.onAttach(), which calls conflicted:::conflicts_register(), which calls conflicted:::is_superset() and rlang::fn_fmls() is called, and chokes on primitives because they have no formals.

If I call library() twice then I have no error and can use the package, including <<- :

library(conflicted)
library(inops)
#> Error: `fn` must be an R function, not a primitive function
library(inops)
2 %in[]% c(1,3)
#> [1] TRUE
x <- 1:4
x < 3 <- 0
x
#> [1] 0 0 3 4

library(conflicted) will be the one failing if it's called second :

library(inops)
#> 
#> Attaching package: 'inops'
#> The following object is masked from 'package:base':
#> 
#>     <<-
library(conflicted)
#> Error: package or namespace load failed for 'conflicted':
#>  .onAttach failed in attachNamespace() for 'conflicted', details:
#>   call: NULL
#>   error: `fn` must be an R function, not a primitive function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions