Is there a way to make R help prompt(with Tab) includes descriptions of all parameters of certain function ( like in Java Doc)?

StackOverflow https://stackoverflow.com/questions/23587662

  •  19-07-2023
  •  | 
  •  

Вопрос

It's inconvinience when I press tab to see how to use parameters of a certain function as in Java Doc in Eclipse, e.g. plot(), and find out there's no descriptions given for some parameters(see figure below). Is it that I didn't install some package providing the complete descriptions of them? Any help would be appriciated.

Это было полезно?

Решение 2

You can get some idea of the arguments to a function with args. Here's an example that describes the arguments of the function strsplit

> args(strsplit)
# function (x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE) 
# NULL

The above call to args shows the arguments to strsplit, and their default settings.

If the function is a closure (see ?closure), a named list of its formal arguments can be seen with formals. View a default setting quickly with the $ operator

> formals(strsplit)$perl
# [1] FALSE

Other information viewable in the console is available by simply entering the function name itself.

> strsplit
# function (x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE) 
# .Internal(strsplit(x, as.character(split), fixed, perl, useBytes))
# <bytecode: 0x26d3388>
# <environment: namespace:base>

Now, plot is a bit different. Since we can't tell a lot about the arguments from

> plot
# function (x, y, ...) 
# UseMethod("plot")
# <bytecode: 0x333a750>
# <environment: namespace:graphics>

we can see that it uses methods. Use methods(plot) and see the different methods. Taking plot.default for example, we can view its R source code with

> plot.default

and a more detailed set of arguments with

> args(plot.default)
# function (x, y = NULL, type = "p", xlim = NULL, ylim = NULL, 
#           log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL, 
#           ann = par("ann"), axes = TRUE, frame.plot = axes, panel.first = NULL, 
#           panel.last = NULL, asp = NA, ...) 
#   NULL

For functions that are in an installed package, you can view some of its information with ::, used as package::function. For example, for the str_extract function in the stringr package,

> stringr::str_extract
# function (string, pattern) 
# {
#     string <- check_string(string)
#     pattern <- check_pattern(pattern, string)
#     positions <- str_locate(string, pattern)
#     str_sub(string, positions[, "start"], positions[, "end"])
# }
# <environment: namespace:stringr>

There is so much more about this topic in the pdfs R Internals and Writing R Extensions.

Другие советы

You can try RStudio IDE. By typing a function, say, plot(), and then press tab, you can see a list of arguments with a brief description. After that, by pressing F1, you can see addition help. I think that satisfies what you need.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top