defining operator doesn't work anymore (Error in UseMethod(“%op%”): no applicable method for '%op%' applied to an object of class “character”)

后端 未结 1 1113
温柔的废话
温柔的废话 2021-01-18 18:40

In my toy package, I have defined %+% operator as an alias to paste0(). Trying to reduce interference with other packages, I realized it the follow

1条回答
  •  伪装坚强ぢ
    2021-01-18 19:38

    To export S3 methods, your NAMESPACE file needs to (in your case) contain the following declarations:

    export(`%+%`)
    S3method(`%+%`, default)
    S3method(`%+%`, character)
    S3method(`%+%`, numeric)
    

    That is, export the %+% generic, and declare S3 methods for the methods.

    Better yet, instead of manually editing the NAMESPACE file use ‘roxygen2’, which generates the correct declarations for you based on the @export documentation tag.

    0 讨论(0)
提交回复
热议问题