Skip to content

Commit

Permalink
Merge pull request #73 from ThinkR-open/clean-temp-files
Browse files Browse the repository at this point in the history
Clean temp files
  • Loading branch information
statnmap authored Jan 27, 2023
2 parents 636e691 + 59ae433 commit cf1fd15
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ cran-comments.md
revdep/
CRAN-RELEASE
CRAN-SUBMISSION
/doc/
/Meta/
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Imports:
utils,
withr
Suggests:
covr,
lifecycle,
renv (>= 0.8.4),
rstudioapi,
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# attachment (development version)
# attachment 0.3.1

## New features

- `find_remotes()` now informs when using "r-universe" repositories.

## Minor changes

- a new parameters `check_if_suggests_is_installed` in `att_amend_desc()` allow not to check if suggested package is installed. (thanks to @yogat3ch)
- `create_renv_for_prod` dont look anymore for suggested packages
- `create_renv_for_prod()` dont look anymore for suggested packages
- Clean a maximum of temp directories after examples and unit tests

# attachment 0.3.0

Expand Down
6 changes: 5 additions & 1 deletion R/att_from_namespace.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
#' @importFrom roxygen2 roxygenise
#'
#' @examples
#' tmpdir <- tempdir()
#' tmpdir <- tempfile(pattern = "namespace")
#' dir.create(tmpdir)
#' file.copy(system.file("dummypackage",package = "attachment"), tmpdir,
#' recursive = TRUE)
#' dummypackage <- file.path(tmpdir, "dummypackage")
#' # browseURL(dummypackage)
#' att_from_namespace(path = file.path(dummypackage, "NAMESPACE"))
#'
#' # Clean temp files after this example
#' unlink(tmpdir, recursive = TRUE)

att_from_namespace <- function(path = "NAMESPACE", document = TRUE, clean = TRUE) {
if (!file.exists(path)) {
Expand Down
15 changes: 12 additions & 3 deletions R/att_to_description.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
#'
#' @export
#' @examples
#' tmpdir <- tempdir()
#' tmpdir <- tempfile(pattern = "description")
#' dir.create(tmpdir)
#' file.copy(system.file("dummypackage",package = "attachment"), tmpdir,
#' recursive = TRUE)
#' dummypackage <- file.path(tmpdir, "dummypackage")
#' # browseURL(dummypackage)
#' att_amend_desc(path = dummypackage)
#' att_amend_desc(path = tmpdir)
#'
#' # Clean after examples
#' unlink(tmpdir, recursive = TRUE)

att_amend_desc <- function(path = ".",
path.n = "NAMESPACE",
Expand Down Expand Up @@ -192,17 +196,22 @@ att_to_desc_from_pkg <- att_amend_desc
#' you may want to set to `FALSE` (no message at all) or `NA` (warning for not installed).
#'
#' @examples
#' tmpdir <- tempdir()
#' tmpdir <- tempfile(pattern = "descfromis")
#' dir.create(tmpdir)
#' file.copy(system.file("dummypackage",package = "attachment"), tmpdir,
#' recursive = TRUE)
#' dummypackage <- file.path(tmpdir, "dummypackage")
#' # browseURL(dummypackage)
#' att_to_desc_from_is(path.d = file.path(dummypackage, "DESCRIPTION"),
#' imports = c("magrittr", "attachment"), suggests = c("knitr"))
#'
#' # In combination with other functions
#' att_to_desc_from_is(path.d = file.path(dummypackage, "DESCRIPTION"),
#' imports = att_from_rscripts(file.path(dummypackage, "R")),
#' suggests = att_from_rmds(file.path(dummypackage, "vignettes")))
#'
#' # Clean temp files after this example
#' unlink(tmpdir, recursive = TRUE)

att_to_desc_from_is <- function(path.d = "DESCRIPTION", imports = NULL,
suggests = NULL, check_if_suggests_is_installed = TRUE, normalize = TRUE,
Expand Down
6 changes: 5 additions & 1 deletion R/create_dependencies_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#' @importFrom utils packageDescription
#'
#' @examples
#' tmpdir <- tempdir()
#' tmpdir <- tempfile(pattern = "depsfile")
#' dir.create(tmpdir)
#' file.copy(system.file("dummypackage",package = "attachment"), tmpdir,
#' recursive = TRUE)
#' dummypackage <- file.path(tmpdir, "dummypackage")
Expand All @@ -23,6 +24,9 @@
#' create_dependencies_file(path = file.path(dummypackage,"DESCRIPTION"),
#' to = file.path(dummypackage, "inst/dependencies.R"),
#' open_file = FALSE)
#'
#' # Clean temp files after this example
#' unlink(tmpdir, recursive = TRUE)

create_dependencies_file <- function(path = "DESCRIPTION",
field = c("Depends", "Imports"),
Expand Down
7 changes: 6 additions & 1 deletion R/set_remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ find_remotes <- function(pkg) {
#' @return Used for side effect. Adds Remotes field in DESCRIPTION file.
#' @export
#' @examples
#' tmpdir <- tempdir()
#' tmpdir <- tempfile(pattern = "setremotes")
#' dir.create(tmpdir)
#' file.copy(system.file("dummypackage", package = "attachment"), tmpdir,
#' recursive = TRUE)
#' dummypackage <- file.path(tmpdir, "dummypackage")
#' # Add remotes field if there are Remotes locally
#' att_amend_desc(dummypackage) %>%
#' set_remotes_to_desc()
#'
#' # Clean temp files after this example
#' unlink(tmpdir, recursive = TRUE)
#'
#' \dontrun{
#' # For your current package
#' att_amend_desc() %>%
Expand Down
6 changes: 5 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ attachment::set_remotes_to_desc()

```{r}
# Copy package in a temporary directory
tmpdir <- tempdir()
tmpdir <- tempfile(pattern = "fakepkg")
dir.create(tmpdir)
file.copy(system.file("dummypackage",package = "attachment"), tmpdir, recursive = TRUE)
dummypackage <- file.path(tmpdir, "dummypackage")
# browseURL(dummypackage)
Expand All @@ -84,6 +85,9 @@ desc_file <- attachment::att_amend_desc(path = dummypackage, inside_rmd = TRUE)
# Add Remotes if you have some installed
attachment::set_remotes_to_desc(path.d = desc_file)
# Clean state
unlink(tmpdir, recursive = TRUE)
```

#### More on finding Remotes repositories (non installed from CRAN)
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ attachment::set_remotes_to_desc()

``` r
# Copy package in a temporary directory
tmpdir <- tempdir()
tmpdir <- tempfile(pattern = "fakepkg")
dir.create(tmpdir)
file.copy(system.file("dummypackage",package = "attachment"), tmpdir, recursive = TRUE)
#> [1] TRUE
dummypackage <- file.path(tmpdir, "dummypackage")
Expand All @@ -99,10 +100,10 @@ desc_file <- attachment::att_amend_desc(path = dummypackage, inside_rmd = TRUE)
#> Please carefully check .Rd files for changes
#> ────────────────────────────────────────────────────────────────────────────────
#>
#> Setting `RoxygenNote` to "7.2.1"
#> Setting `RoxygenNote` to "7.2.2"
#> ℹ Loading dummypackage
#> Writing ']8;;file:///tmp/RtmpB3u77H/dummypackage/NAMESPACENAMESPACE]8;;'
#> Writing ']8;;file:///tmp/RtmpB3u77H/dummypackage/NAMESPACENAMESPACE]8;;'
#> Writing ']8;;file:///tmp/Rtmpe9Zik8/fakepkg4c0f84cd8072f/dummypackage/NAMESPACENAMESPACE]8;;'
#> Writing ']8;;file:///tmp/Rtmpe9Zik8/fakepkg4c0f84cd8072f/dummypackage/NAMESPACENAMESPACE]8;;'
#> ℹ Loading dummypackage
#> Package(s) Rcpp is(are) in category 'LinkingTo'. Check your Description file to be sure it is really what you want.
#>
Expand All @@ -114,6 +115,9 @@ desc_file <- attachment::att_amend_desc(path = dummypackage, inside_rmd = TRUE)
attachment::set_remotes_to_desc(path.d = desc_file)
#> There are no remote packages installed on your computer to add to description
#> NULL

# Clean state
unlink(tmpdir, recursive = TRUE)
```

#### More on finding Remotes repositories (non installed from CRAN)
Expand All @@ -122,8 +126,8 @@ Find packages installed out of CRAN. This helps fill the “Remotes” field
in DESCRIPTION file with `set_remotes_to_desc()`.
Behind the scene, it uses `fund_remotes()`.

- See the examples below if {fusen} is installed from GitHub
- Also works for GitLab, Bioconductor, Git, Local installations
- See the examples below if {fusen} is installed from GitHub
- Also works for GitLab, Bioconductor, Git, Local installations

``` r
# From GitHub
Expand Down
20 changes: 9 additions & 11 deletions dev/dev_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"))
out <- checkhelper::find_missing_tags()
View(out)

all_files_to_clean <- checkhelper::check_clean_userspace(pkg = ".")
View(all_files_to_clean)

# Check spelling
# usethis::use_spell_check()
spelling::spell_check_package()
Expand Down Expand Up @@ -155,27 +158,22 @@ devtools::check_mac_release()
# sudo apt-get install biber texlive-science texlive-lang-french texlive-lang-english texlive-fonts-extra
checkhelper::check_as_cran()

debugonce(tools:::.check_packages_used_in_tests)
tools:::.check_packages_used_in_tests(dir = ".", testdir = "tests/testthat")
db <- tools:::.read_description("DESCRIPTION")
testdir <- "tests/testthat"
Rinfiles <- list.files(testdir, pattern = "\\.Rin$", full.names = TRUE)
Rfiles <- list.files(testdir, pattern = "\\.[rR]$", full.names = TRUE)
res <- tools:::.check_packages_used_helper(db, c(Rinfiles, Rfiles))
res
?withr::with_connection()
tools:::.get_standard_repository_URLs()

# Check reverse dependencies
# remotes::install_github("r-lib/revdepcheck")
usethis::use_git_ignore("revdep/")
usethis::use_build_ignore("revdep/")

devtools::revdep()

# remotes::install_github('r-lib/revdepcheck')
id <- rstudioapi::terminalExecute("Rscript -e 'remotes::install_github(\"r-lib/revdepcheck\", upgrade = \"never\")'")
rstudioapi::terminalKill(id)

library(revdepcheck)
# In another session
revdepcheck::revdep_todo()
# revdepcheck::revdep_add(packages = "fusen")
# revdepcheck::revdep_check(num_workers = 4)
id <- rstudioapi::terminalExecute("Rscript -e 'revdepcheck::revdep_check(num_workers = 4)'")
rstudioapi::terminalKill(id)
# See outputs
Expand Down
8 changes: 6 additions & 2 deletions man/att_amend_desc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/att_from_namespace.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/att_to_desc_from_is.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/attachment-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/create_dependencies_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/set_remotes_to_desc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf1fd15

Please sign in to comment.