Override a function that is imported in a namespace

前端 未结 3 1496
梦谈多话
梦谈多话 2020-11-29 04:46

As the termplot function in R is containing some weird code that is giving me annoying bugs, I want to override it in my own test code until I find a more perma

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 05:02

    I think the trace() function does automatically what is attempted above. Do:

    trace('termplot', edit='gedit')
    

    Where 'gedit' is the name of a text editor. The editor will open with the original code and you can paste whatever substitution code you desire.

    To return to the original version just untrace('termplot')

    Caveat: I tried using this when the text editor had many files open and it didn't work. So I use 'gedit', a text editor on my system that I don't use often. This way I am sure that R will open a new instance of 'gedit'.

    I'm not positive this will help, but I think it's worth a try. The search sequence when there are namespaces is really confusing.

提交回复
热议问题