When we have defined tens of functions – probably to develop a new package – it is hard to find out the name of a specific variable among many function names through ls() command.
In most of cases we are not looking for a function name – we already know they exist – but we want to find what was the name we assigned to a variable.
Any idea to solve it is highly appreciated.
If you want a function to do this, you need to play around a bit with the environment that
ls()looks in. In normal usage, the implementation below will work by listing objects in the parent frame of the function, which will be the global environment if called at the top level.I’ve written this so you can pass in the
nameargument ofls()if you need to call this way down in a series of nested function calls.Note also we need to
get()the objects named byls()when we test if they are a function or not.