I have a few questions about {usethis}

I hope it's ok just to post them here. Hoping for clarification or explanation about a couple of things - no urgency for answers.

  • Why does use_testthat() refuse to work in a non-package project? Surely it's legitimate to use testthat() in projects that are not set up to be packages?
  • Ditto but for use_mit_licence(). It seems strange that a decision would be made in the design of usethis() that it can only be used to facilitate adding a licence to packages. What am I not understanding? (This was already asked here but I don't think there was a satisfactory answer).

My next question is a different kind - it's more like a feature request. I like having things like {reprex} loaded automatically in my .Rprofile, and {usethis} is a good helper for this practice with functions like use_reprex().

I understand the difference between workflow packages like this that can legitimately be auto-loaded with a new R session, as opposed to packages 'internal' to a project that should not be auto-loaded for reproducibility reasons. I'm wondering if git packages like {git2r} or {gert} would also count as workflow packages that could be auto-loaded - I think they could. And whether it would be good to have a usethis function that facilitated that.

Basically I'm just realising at last that, in principle, I'd be happier interacting with git via typing functions in the R console in RStudio, rather than using the Git pane in RStudio, which I don't like so much (no complaint, just personal preference). And to know that I'd always have those git functions ready to run without having to load the package manually.

Is there any reason why it would not be a good idea to auto-load {git2r} via my .Rprofile?

I was also wondering about {here} being auto-loaded via .Rprofile, but I think would not be a good idea as it's something more internal to project scripts and auto-loading would break reproducibility. I just love {here} and it feels like the kind of thing that should always be there for users, somehow!

1 Like

Great question. Hopefully it will attract Jenny Bryant's notice for more insight than I can give.

Looking at use_testthat

function () 
{
    check_is_package("use_testthat()")
    check_installed("testthat")
    use_dependency("testthat", "Suggests")
    use_directory(path("tests", "testthat"))
    use_template("testthat.R", save_as = path("tests", "testthat.R"), 
        data = list(name = project_name()))
    ui_todo("Call {ui_code('use_test()')} to initialize a basic test file and open it \\\n    for editing.")
}

the function was designed solely for use in the context of package development.

But, all that's needed to be a package is a DESCRIPTION file in the working directory, plus whatever canned directory and files that the various usethis functions expect. (But no promise, since I'm not actually, myself, personally, a packager.)

Likewise, with use_mit_license and siblings

{
    force(name)
    check_is_package("use_mit_license()")
    use_description_field("License", "MIT + file LICENSE", overwrite = TRUE)
    use_license_template("mit", name)
    use_template("license-mit.txt", save_as = "LICENSE", data = license_data(name))
}

yes, it's designed as a packaging component, but should (says the man who's probably not going to get around to trying it first) be relatively easy to adapt.

More from the guy who hasn't gotten around to doing it himself: When I was spending more time in Python I finally got tired enough of tracking down snippets, I made my own util package to import for the good of the cause. On on the next One of These Days, I'm gonna get around to doing the equivalent for an R package. So then .Rprofile can be the bare essentials, util will be the full kit, and specific projects will have either libraries manually attached or namespace attached (through a process I have yet to understand).

Now I'll veer off into the realm of personal choices: 1) should the fabulous here be in .Rprofile, util or as needed? and 2) should gitwork be via pane, package or system? These are intimate questions that must be considered in private between the user and R counselor. :grin:

Thanks for bringing a chance to wax philosophical!

1 Like

Thanks @technocrat for looking behind the curtain a bit for me.

Yeah, there's of course nothing stopping me manually adding whatever licence I want, nor using {testthat}, I was just curious about the design choices in the relevant functions.

I don't need a discussion about RStudio gitwork UI preferences - I agree those are just personal preferences.
I'm pretty sure it's not a good idea to add {here} in .Rprofile, I'll withdraw that question!

I haven't used {testthat} before but just starting a new side project I thought it might be a good idea to start! Similarly, am new-ish to {usethis} and just wondering how it can help me.

1 Like

I just learned from watching this video that Danielle Navarro, for one, has git2r, testthat, usethis, roxygen2 and maybe a few other non-core packages auto-loaded at startup in her R profile. I'm going to add git2r, at least, to mine.

1 Like