Giter VIP home page Giter VIP logo

usethis's Introduction

usethis usethis website

R-CMD-check CRAN status Lifecycle: stable .github/workflows/R-CMD-check Codecov test coverage

usethis is a workflow package: it automates repetitive tasks that arise during project setup and development, both for R packages and non-package projects.

Installation

Install the released version of usethis from CRAN:

install.packages("usethis")

Or install the development version from GitHub with:

# install.packages("pak")
pak::pak("r-lib/usethis")

Usage

Most use_*() functions operate on the active project: literally, a directory on your computer. If you’ve just used usethis to create a new package or project, that will be the active project. Otherwise, usethis verifies that current working directory is or is below a valid project directory and that becomes the active project. Use proj_get() or proj_sitrep() to manually query the project and read more in the docs.

A few usethis functions have no strong connections to projects and will expect you to provide a path.

usethis is quite chatty, explaining what it’s doing and assigning you tasks. βœ” indicates something usethis has done for you. ☐ indicates that you’ll need to do some work yourself.

Below is a quick look at how usethis can help to set up a package. But remember, many usethis functions are also applicable to analytical projects that are not packages.

library(usethis)

# Create a new package -------------------------------------------------
path <- file.path(tempdir(), "mypkg")
create_package(path)
#> βœ” Creating '/tmp/Rtmpyt1hd6/mypkg/'.
#> βœ” Setting active project to "/private/tmp/Rtmpyt1hd6/mypkg".
#> βœ” Creating 'R/'.
#> βœ” Writing 'DESCRIPTION'.
#> Package: mypkg
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#>     * First Last <[email protected]> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#>     license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.3.2
#> βœ” Writing 'NAMESPACE'.
#> βœ” Setting active project to "<no active project>".
# only needed since this session isn't interactive
proj_activate(path)
#> βœ” Setting active project to "/private/tmp/Rtmpyt1hd6/mypkg".
#> βœ” Changing working directory to '/tmp/Rtmpyt1hd6/mypkg/'

# Modify the description ----------------------------------------------
use_mit_license("My Name")
#> βœ” Adding "MIT + file LICENSE" to 'License'.
#> βœ” Writing 'LICENSE'.
#> βœ” Writing 'LICENSE.md'.
#> βœ” Adding "^LICENSE\\.md$" to '.Rbuildignore'.

use_package("ggplot2", "Suggests")
#> βœ” Adding ggplot2 to 'Suggests' field in DESCRIPTION.
#> ☐ Use `requireNamespace("ggplot2", quietly = TRUE)` to test if ggplot2 is
#>   installed.
#> ☐ Then directly refer to functions with `ggplot2::fun()`.

# Set up other files -------------------------------------------------
use_readme_md()
#> βœ” Writing 'README.md'.
#> ☐ Update 'README.md' to include installation instructions.

use_news_md()
#> βœ” Writing 'NEWS.md'.

use_test("my-test")
#> βœ” Adding testthat to 'Suggests' field in DESCRIPTION.
#> βœ” Adding "3" to 'Config/testthat/edition'.
#> βœ” Creating 'tests/testthat/'.
#> βœ” Writing 'tests/testthat.R'.
#> βœ” Writing 'tests/testthat/test-my-test.R'.
#> ☐ Edit 'tests/testthat/test-my-test.R'.

x <- 1
y <- 2
use_data(x, y)
#> βœ” Adding R to 'Depends' field in DESCRIPTION.
#> βœ” Creating 'data/'.
#> βœ” Setting 'LazyData' to "true" in 'DESCRIPTION'.
#> βœ” Saving "x" and "y" to "data/x.rda" and "data/y.rda".
#> ☐ Document your data (see <https://r-pkgs.org/data.html>).

# Use git ------------------------------------------------------------
use_git()
#> βœ” Initialising Git repo.
#> βœ” Adding ".Rproj.user", ".Rhistory", ".Rdata", ".httr-oauth", ".DS_Store", and
#>   ".quarto" to '.gitignore'.

Code of Conduct

Please note that the usethis project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

usethis's People

Contributors

ateucher avatar batpigandme avatar cderv avatar coatless avatar craigcitro avatar davisvaughan avatar geoff99 avatar hadley avatar ijlyttle avatar jdblischak avatar jennybc avatar jeroen avatar jimhester avatar jmgirard avatar jonthegeek avatar kevinushey avatar kohske avatar krlmlr avatar lionel- avatar maelle avatar malcolmbarrett avatar maurolepore avatar mine-cetinkaya-rundel avatar olivroy avatar pat-s avatar robertzk avatar rorynolan avatar tracykteal avatar wch avatar yoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usethis's Issues

use_tidy_eval

Same strategy as pipe

  • Import rlang
  • Re-export: sym(), syms(), ensym(), quo(), quos(), enquo(), expr(), exprs(), enexpr()

Badging for project lifecycle

I greatly enjoy using the use_* commands to get the markdown for my README badges. Curious what your team thinks of the http://www.repostatus.org/ badges, and if you would consider a l'lil function to generate the appropriate badge. I know there's some risk of these becoming stale since they are just static badges, but personally I find the categories quite helpful, particularly on the sunset era of a package.

export use_directory()

Could you please export use_directory()? I know that its pretty simple, but useful if you want to create your own use_* functions. If you decide that that this is a good idea, I can write the roxygen for it.

create_package does not correctly normalize the path for everything

usethis::create_package("~/p/xyz")
#> βœ” Creating 'xyz/'
#> βœ” Creating 'R/'
#> βœ” Creating 'man/'
#> βœ” Writing 'DESCRIPTION'
#> βœ” Writing 'NAMESPACE'
#> βœ” Writing 'xyz.Rproj'
#> βœ” Adding '.Rproj.user' to './.gitignore'
#> βœ” Adding '^.*\\.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
#> The file /Users/jhester/~/p/xyz/xyz.Rproj does not exist.

use_git_ignore()

and perhaps use_ignore() which adds to both .Rbuildignore and .gitignore.

Handle host for use_github() same way as auth_token

Issue by jennybc
Wednesday Sep 07, 2016 at 23:33 GMT
Originally opened as r-lib/devtools#1333


I propose handling the host for use_github() in a similar fashion as auth_token, which is this:

  • by default, helper function github_pat() is called, which tries to retrieve PAT from env var GITHUB_PAT

Could we use an env var named GITHUB_API_URL for this? I suggest it because gh already does this. If GITHUB_API_URL is not defined, then use existing default https://api.github.com.

This makes it easier to define a user-level GITHUB_PAT for github.com and, for individual projects, store an alternative host and PAT for GitHub Enterprise in a project-level .Renviron.

cc @ijlyttle

integrate with clipr?

It might be useful for things where you have to copy paste if the text was automatically added to the clipboard with clipr.

It is true if there is more than one thing to copy paste only the last one would be on the clipboard, but at least it is something. Also some people (me at least) use utilities that can save and retrieve clipboard history.

use_partial_warnings

options(
  warnPartialMatchArgs = TRUE,
  warnPartialMatchDollar = TRUE,
  warnPartialMatchAttr = TRUE
)

Consult Urban Dictionary in setup() and release()

Issue by krlmlr
Wednesday Aug 31, 2016 at 11:18 GMT
Originally opened as r-lib/devtools#1315


for the package name. Per Hadley's PSA.

Can use the udapi package. With Ironholds/udapi#1, we get:

print(get_term("PSA")[1:3,])
  • (+1196/-143) Publice Service Announcement. Rarely used as an acronym.

    This following snow warning is a public service announcement.

  • (+228/-196) A protein made specifically by the prostate gland -- Prostate Specific Antigen. It is
    measured by a blood test, and is used for screening for prostate cancer and checking for the
    results of treating that disease.

    James saw his doctor today, since he was upset that his PSA was over ten thousand (normal is
    up to four). Then he went to make final arrrangements.

  • (+158/-143) Pacific Southwest Airlines headquartered in San Diego, California. Featured
    Smileliners (Airplanes with smiles painted on the nose). Purchased by USAir in 1987

    "PSA, Catch our smile!"

Quiet option for use_coverage()

It should:

  • ask the user for a target percentage for the project (say 70% by default)
  • set the patch target to zero
  • set both thresholds to 100%
comment: false

coverage:
  status:
    project:
      default:
        target: 70
        threshold: 100
    patch:
      default:
        target: 0
        threshold: 100

use_roxygen_md()

  • Use roxygen2md to convert if roxygen already in use
  • Setup Roxygen metadata in DESCRIPTION

update .gitignore in vignettes folder with `use_vignette()`?

(migrated from r-lib/devtools#1547)

To ignore .R and .html files generated when knitting .Rmd documents. This is desired because calls to e.g.

devtools::document(roclets = "vignette")

will drop the generated .R and .html files within the vignettes folder after completion. Note that RStudio users can opt-in to having this roclet run on Build and Reload within the IDE, so it's likely that such users will have these files sitting in the vignettes folder after a package build.

Implement `use_depsy_badge`

Depsy is a NSF funded project that consists on

[A] free website launched in November 2015 that aims to β€œmeasure the value of software that powers science”. (nature, Jan 2016)

In simple terms, Depsy provides the unsung heroes of scientific software with a simple way of measuring the value of their contribution to the scientific community.

In practice, Depsy ranks software (published on PyPI and CRAN) and provides information about usage and citation of those software projects. Ultimately, such rank can be reported on a project website with a badge, e.g. the devtools Depsy badge: Research software impact.

I think having a use_depsy_badge function would be nice. If you think so too, I can provide a PR with such functionality based on this issue as a wrapper of use_badge.

Typo in devtools::use_readme_rmd appending .Rbuildignore?

Issue by tpq
Monday Aug 22, 2016 at 00:06 GMT
Originally opened as r-lib/devtools#1295


This is a very minor issue, but when calling use_readme_rmd(), .Rbuildignore seems to get populated with: *^README\.Rmd$ and *^README-.*\.png$. However, knitr renders images to *^README_*\.png$. I think the hyphen might need to get changed in an underscore.

use_rmarkdown_template

If you want your package to provide an RMarkdown template (such as in rtciles, rmdshower etc then there's quite a few directories you need to get right. Such as:

inst/rmarkdown/templates/<templatename>
inst/rmarkdown/templates/<templatename>/template.yml
inst/rmarkdown/templates/<templatename>/skeleton
inst/rmarkdown/templates/<templatename>/skeleton/skeleton.Rmd

A use_rmarkdown_template could help.

PR inbound.

Convenience function to generate roxygen comment blocks

It'd be nice to have a convenience function to create roxygen comment blocks automatically. This would be similar to utils::prompt, but instead of creating Rd files, it would print out roxygen comment blocks Perhaps make it S3, with methods for functions and data.frames? I'm thinking something like this:

> myfun <- function(a, b, ..., d) NULL
> use_roxygen_comments(myfun)
#' <Title>
#' 
#' <Description>
#' 
#' @param a <parameter description>
#' @param b <parameter description>
#' @param ... <parameter description>
#' @param d <parameter description>
#' @return <describe returned object
#' @seealso <links to other help pages>
#' @export

use_usethis

Opens ~/.Rprofile and gives code block to load in interactive sessions.

idea: use_pipe()?

Issue by ijlyttle
Sunday Jul 10, 2016 at 13:45 GMT
Originally opened as r-lib/devtools#1258


Given the emergence of the idea of Tidy API's, which encourages use of the pipe, could it be useful to provide a function use_pipe() that would create a pipe.R file like this? h/t @ramnathv here.

I see the plus side as making it easier to use "your" package functions not having to load magrittr explicitly.

I see a drawback (potentially) if every package exports the pipe, could that be messy/problematic? (Honestly, I don't know.)

Thoughts?

use_cla()

It would be nice to have a helper setup a Contributor License Agreement for a project. Using https://cla-assistant.io/ all you need is a GitHub gist with the CLA text, I just set one up for covr derived from https://cla.github.com.

I like the GitHub CLA because it is short and pretty readable even for a layperson like myself.

Clipboard integration

The functions that say "add this to that file" could use clipr::write_clip() to simplify the user's task.

create_package creating a directory

For usethis, isn't setting the path once the package is created a little awkward (as done in the README file)? Almost everything from devtools is done inside the package directory. create_package could create the package files and subdirectories in the current path instead.

use_package() and Remotes

It would be nice to specify you depend on the dev version of a package, i.e. to populate Remotes in DESCRIPTION. I feel like this issue is already open somewhere -- maybe even by me? -- but I sure can't find it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.