I am trying to check if a specific variable or function exists in a package. For example, suppose I wanted to check if a function called plot existed in the "graph" of the package.
The following tests: is there a plot function, but not the package it comes from:
exists('plot', mode='function')
Or I can verify that there is something called plot in the graphics package, but that does not tell me if this is a function:
'plot' %in% ls('package:graphics')
Is there a good way to ask: "is there an object named X in package Y of mode Z"? (essentially, can I limit exists specific package?)
(Yes, I can combine the two lines above to first check that the plot is in graphics and then request the plot mode, but what if I had my own function plot masking graphics::plot ? Can I trust the conclusions exists('plot', mode='function') ?)
Background information: writing tests for my package and checking that various functions are exported. I use the testthat package, which runs tests in an environment where I can see all the internal functions of the package, and was stung by the fact that exists('myfunction', mode='function') returns true, but I actually forgot to export myfunction . I want to check if various functions are exported.
source share