0
 rm(list=ls())

I have a function in the global environment, and after executing the above command, that function is still there. I know because I can still call that function and

pryr::where('function_name')

returns the global environment

Why is that?

  • 4
    See what's wrong with using `rm(list=ls())` here: https://www.tidyverse.org/blog/2017/12/workflow-vs-script/. There are many things it doesn't "reset". But I find it hard to believe it won't remove a function. Does the function name begin with a `.` so it's not returned by `ls()`? We'd need to see a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) here. – MrFlick Mar 04 '20 at 20:12
  • @MrFlick yes, the function does start with a dot. why does that matter? – Bear Bile Farming is Torture Mar 04 '20 at 20:13
  • It's not clear to me what your particular issue is. Please show an example of a session that illustrates what you're talking about. – Dason Mar 04 '20 at 20:13
  • 2
    @unathletic_coder - Oh yeah that absolutely matters. You need to use ls(all=TRUE) to remove things that start with dots as well – Dason Mar 04 '20 at 20:13
  • 3
    Variables that start with a `.` are "hidden" by convention. In order to get `ls()` to return those values as well, use `ls(all.names = TRUE)`. – MrFlick Mar 04 '20 at 20:14
  • Looks like the package pryr is the source of your function- rm(list=ls()) won't dettach a package – rg255 Mar 04 '20 at 20:15

0 Answers0