Skip to content

use_test() without arguments fails with RStudio project under ~ on Windows #901

@mikmart

Description

@mikmart

File path checking seems to go wrong when use_test() tries to get the path to the active file in RStudio in a project under ~ on Windows:

usethis::use_r("foo.R")
# ✔ Setting active project to 'C:/Users/mikko/Documents/R/dev/foo'
# ● Modify 'R/foo.R'
usethis::use_test()
# ✔ Adding 'testthat' to Suggests field in DESCRIPTION
# ✔ Creating 'tests/testthat/'
# ✔ Writing 'tests/testthat.R'
# ● Call `use_test()` to initialize a basic test file and open it for editing.
# Error: Open file must be in the 'R/' directory of the active package.
# * Actual path: 'Users/mikko/R/dev/foo/R/foo.R'
rstudioapi::getSourceEditorContext()$path
# [1] "~/R/dev/foo/R/foo.R"
usethis:::proj_path_prep(rstudioapi::getSourceEditorContext()$path)
# C:/Users/mikko/Documents/R/dev/foo/Users/mikko/R/dev/foo/R/foo.R

Related r-lib/fs#221. Maybe related #485?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions