Skip to content

A mechanism for package author to register some options for autocomplete in RStudio IDE #8702

Open

Description

@cderv

Idea

Currently, the IDE will allow autocompletion of options in options() only for the option which has been already set.

As some of our package relies on options for configurations, it would be nice to have a way to quickly access all the option available for a package using autocompletion, the same way we can access all available function using pkg:: then tabulation.

Context about the need

This comes again from blogdown development where we use a lot of options that the user could use to configure the behavior. This is definitely not the only package.
Usually, these options can be found in documentation (like with ?future::future.options), NEWS, README or other. It can also be found by reading the code of the function on github.

Having a way to access by autocompletion some options that a package developer would like its users to discover would be great.

For blogdown, @yihui added a trick of initializing all the options so that the IDE would know about it. This led to initialize them to NA and have a specific wrapper get_option so that if it was NA it should be considered unset (like NULL) - this is because setting an option to NULL is like unsetting them so the IDE does not see it.
See what we have done in rstudio/blogdown@baeca2f

You can see the effet in RStudio

  • Open RStudio
  • try options(blog then Tab for completion
  • Load blogdown - library(blogdown)
  • Redo the options(blog and see the difference.

About what could be offered.

To be flexible and extensible this could require a mechanism for a package author to register some options for its package to be found. This could also require a convention like 'pkg.` to be respected and a mechanism to register the option. Or maybe a convention of a function / object or file that if present in the package would contain the option to use for autocompletion.

Thanks for considering.

Activity

  1. added
    autocompletion
    on Jan 8, 2021
  2. yihui commented on Jan 8, 2021

    @yihui
    Contributor

    I think such a mechanism exists in the IDE, and we just need a way to let users register the option names somewhere. For example, the IDE can autocomplete knitr chunk options:

    image

    This is because knitr:::opts_chunk_attr has provided the candidates. Other packages (e.g. blogdown) could also provide this list of candidates, and the IDE can use this list to autocomplete options().

  3. added this to the Later milestone on Feb 16, 2021
  4. added a commit that references this issue on Mar 25, 2021
  5. moved this from Backlog to Need External Work in R Markdown Team Projectson Nov 2, 2021
  6. olivroy commented on Sep 6, 2023

    @olivroy
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autocompletionenhancement

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions