2

Quick question - hoping for some help.

I'm practicing in R. I type this into the console:

?mtcars

And I see in the bottom-right hand quadrant of RStudio information about mtcars.

Later on, I'm trying to convert something as a factor:

mtcars$am <-as_factor(mtcars$am)

But I get this error message:

Error in as_factor(mtcars$am) : could not find function "as_factor"

So I try to explore what that means by looking at the help section:

?as_factor

But I get this error message:

No documentation for ‘as_factor’ in specified packages and libraries:
you could try ‘??as_factor’

I follow the advice and see that as factor is in the forcats library, which I guess I didn't have loaded.

How should I think about the difference between looking for help documentation using one question mark ?mtcars vs two question marks ??as_factor? Is there a heuristic for this?

Henrik
  • 65,555
  • 14
  • 143
  • 159
hachiko
  • 671
  • 7
  • 20
  • 6
    `?` searches in *loaded* packages, whereas `??` extends the search to *installed* packages. – Rui Barradas Jul 11 '21 at 19:39
  • 3
    You can search "?help.search" – akrun Jul 11 '21 at 19:39
  • 2
    Or you can type `?\`??\``. – Martin Gal Jul 11 '21 at 19:43
  • 1
    @MartinGal, I feel like that's a recursive answer ... to be able to know to try `?\`??\``, you need to know what `?`, but can you `?\`?\`` (which doesn't work, btw)? Should one think to do that? (This is not a criticism, kind of the Inception of answering "what is `?`/`??`".) – r2evans Jul 11 '21 at 19:45
  • 1
    @r2evans Actually `?\`?\`` does work (at least on my machine). Basically you *are* right, but I was curious, if `?\`??\`` does work and I thought it was a funny comment. On the other hand: I didn't even know that `??` existed, but I used `?` before. So... is it really recursive? – Martin Gal Jul 11 '21 at 19:55
  • 1
    Also relevant/recommended/required reading: [R-Intro 1.7 Getting help with functions and features](https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Getting-help) – Henrik Jul 11 '21 at 20:03
  • 2
    (@MartinGal, for me, `?\`?\`` does not work, using emacs/ess. To see it, I need to use `help("?")`. \*shrug\*) – r2evans Jul 11 '21 at 20:17

0 Answers0