Skip to content

Commit

Permalink
Merge pull request #50 from ThinkR-open/47-escape-line
Browse files Browse the repository at this point in the history
v0.2.5 - Prepare for CRAN
  • Loading branch information
statnmap authored May 15, 2022
2 parents bb024ee + d5c3aa4 commit 074a140
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: attachment
Title: Deal with Dependencies
Version: 0.2.4.9001
Version: 0.2.5
Authors@R:
c(person(given = "Sébastien",
family = "Rochette",
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# attachment 0.2.4.900x
# attachment 0.2.5
## Major changes

* add `create_renv_for_dev()` and `create_renv_for_prod()` function to create `renv.lock` file based on development project (@VincentGuyader and @statnmap).
* Quarto documents can be parsed with `att_from_rmds()`.
* Documentation for bookdown and quarto dependencies extraction updated

## Minor changes

* `att_amend_desc()` now saves file before processing
* Newline escape code `\n` will not interfere with package discovery

# attachment 0.2.4

Expand Down
10 changes: 8 additions & 2 deletions R/att_from_rmds.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ att_from_rmd <- function(path, temp_dir = tempdir(), warn = -1,
yaml <- c("\n# yaml to parse \n",
paste(yaml_pkg, "\n"))
cat(yaml, file = r_file, append = TRUE)
att_from_rscript(r_file)
res <- att_from_rscript(r_file)

# clean tempdir
file.remove(runR)
file.remove(r_file)

return(res)
}

#' Get all packages called in vignettes folder
Expand All @@ -81,7 +87,7 @@ att_from_rmd <- function(path, temp_dir = tempdir(), warn = -1,

#' @export
att_from_rmds <- function(path = "vignettes",
pattern = "*.[.](Rmd|rmd)$",
pattern = "*.[.](Rmd|rmd|qmd)$",
recursive = TRUE, warn = -1,
inside_rmd = FALSE, inline = TRUE) {

Expand Down
2 changes: 2 additions & 0 deletions R/att_from_rscripts.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
att_from_rscript <- function(path) {

file <- as.character(parse(path))
# Replace newlines `\n` by space
file <- gsub("\\\\n", " ", file)

pkg_points <- file %>%
.[grep("^#", ., invert = TRUE)] %>%
Expand Down
24 changes: 16 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,27 @@ for (i in to_install) {
}
```

### For bookdown
### For bookdown, pagedown, quarto

If you write a {bookdown} and want to publish it on Github using Travis for instance, you will need a DESCRIPTION file with list of dependencies just like for a package. In this case, you can use the function to description from import/suggest: `att_to_desc_from_is()`.
If you write a {bookdown} and want to publish it on Github using GitHub Actions or GitLab CI for instance, you will need a DESCRIPTION file with list of dependencies just like for a package. In this case, you can use the function to description from import/suggest: `att_to_desc_from_is()`.

```{r, eval=FALSE}
usethis::use_description()
# bookdown Imports are in Rmds
imports <- c("bookdown", attachment::att_from_rmds("."))
attachment::att_to_desc_from_is(path.d = "DESCRIPTION",
imports = imports, suggests = NULL)
```

Then, install dependencies with
```{r, eval=FALSE}
remotes::install_deps()
```


### To list information
Of course, you can also use {attachment} out of a package to list all package dependencies of R scripts using `att_from_rscripts()` or Rmd files using `att_from_rmds()`.

Of course, you can also use {attachment} out of a package to list all package dependencies of R scripts using `att_from_rscripts()` or Rmd/qmd files using `att_from_rmds()`.
If you are running this inside a Rmd, you may need parameter `inside_rmd = TRUE`.

```{r, eval=TRUE}
Expand All @@ -131,17 +138,18 @@ att_from_rscripts(path = dummypackage)
att_from_rmds(path = file.path(dummypackage, "vignettes"), inside_rmd = TRUE)
```

## Vignette
## Vignettes

Package {attachment} has a vignette to present the different functions available. There is also a recommendation to have a `dev_history.R` in the root directory of your package. (*Have a look at [dev_history.R](https://github.com/ThinkR-open/attachment/blob/main/dev/dev_history.R) in the present package*)
Package {attachment} has vignettes to present the different functions available. There is also a recommendation to have a `dev_history.R` in the root directory of your package. (*Have a look at [dev_history.R](https://github.com/ThinkR-open/attachment/blob/main/dev/dev_history.R) in the present package*)

```{r, eval=FALSE}
vignette("fill-pkg-description", package = "attachment")
vignette("a-fill-pkg-description", package = "attachment")
vignette("b-bookdown-and-scripts", package = "attachment")
vignette("use_renv", package = "attachment")
```

The vignette is available on the {pkgdown} page: <https://thinkr-open.github.io/attachment/articles/fill-pkg-description.html>
The vignettes are available on the {pkgdown} page, in the "Articles" menu: <https://thinkr-open.github.io/attachment/>

See full documentation realized using {pkgdown} at <https://thinkr-open.github.io/attachment/>

## Code of Conduct

Expand Down
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ dummypackage <- file.path(tmpdir, "dummypackage")
# browseURL(dummypackage)
att_amend_desc(path = dummypackage, inside_rmd = TRUE)
#> Updating dummypackage documentation
#> Updating roxygen version in /tmp/RtmpdAJaCu/dummypackage/DESCRIPTION
#> Updating roxygen version in /tmp/RtmpK2L9Ud/dummypackage/DESCRIPTION
#> ℹ Loading dummypackage
#> Writing NAMESPACE
#> Writing NAMESPACE
#> Package(s) Rcpp is(are) in category 'LinkingTo'. Check your Description file to be sure it is really what you want.
#> [-] 1 package(s) removed: utils.
#> [+] 2 package(s) added: stats, ggplot2.
#> [+] 2 package(s) added: stats, glue.
```

### For installation
Expand Down Expand Up @@ -130,24 +130,32 @@ for (i in to_install) {
}
```

### For bookdown
### For bookdown, pagedown, quarto

If you write a {bookdown} and want to publish it on Github using Travis
for instance, you will need a DESCRIPTION file with list of dependencies
just like for a package. In this case, you can use the function to
description from import/suggest: `att_to_desc_from_is()`.
If you write a {bookdown} and want to publish it on Github using GitHub
Actions or GitLab CI for instance, you will need a DESCRIPTION file with
list of dependencies just like for a package. In this case, you can use
the function to description from import/suggest:
`att_to_desc_from_is()`.

``` r
usethis::use_description()
# bookdown Imports are in Rmds
imports <- c("bookdown", attachment::att_from_rmds("."))
attachment::att_to_desc_from_is(path.d = "DESCRIPTION",
imports = imports, suggests = NULL)
```

Then, install dependencies with

``` r
remotes::install_deps()
```

### To list information

Of course, you can also use {attachment} out of a package to list all
package dependencies of R scripts using `att_from_rscripts()` or Rmd
package dependencies of R scripts using `att_from_rscripts()` or Rmd/qmd
files using `att_from_rmds()`.
If you are running this inside a Rmd, you may need parameter
`inside_rmd = TRUE`.
Expand All @@ -158,26 +166,25 @@ dummypackage <- system.file("dummypackage", package = "attachment")
att_from_rscripts(path = dummypackage)
#> [1] "stats" "testthat" "dummypackage"
att_from_rmds(path = file.path(dummypackage, "vignettes"), inside_rmd = TRUE)
#> [1] "knitr" "rmarkdown" "ggplot2"
#> [1] "knitr" "rmarkdown" "glue"
```

## Vignette
## Vignettes

Package {attachment} has a vignette to present the different functions
Package {attachment} has vignettes to present the different functions
available. There is also a recommendation to have a `dev_history.R` in
the root directory of your package. (*Have a look at
[dev\_history.R](https://github.com/ThinkR-open/attachment/blob/main/dev/dev_history.R)
[dev_history.R](https://github.com/ThinkR-open/attachment/blob/main/dev/dev_history.R)
in the present package*)

``` r
vignette("fill-pkg-description", package = "attachment")
vignette("a-fill-pkg-description", package = "attachment")
vignette("b-bookdown-and-scripts", package = "attachment")
vignette("use_renv", package = "attachment")
```

The vignette is available on the {pkgdown} page:
<https://thinkr-open.github.io/attachment/articles/fill-pkg-description.html>

See full documentation realized using {pkgdown} at
<https://thinkr-open.github.io/attachment/>
The vignettes are available on the {pkgdown} page, in the “Articles”
menu: <https://thinkr-open.github.io/attachment/>

## Code of Conduct

Expand Down
13 changes: 9 additions & 4 deletions dev/dev_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"))

# Check content
# remotes::install_github("ThinkR-open/checkhelper")
checkhelper::find_missing_tags()
out <- checkhelper::find_missing_tags()
View(out)

# Check spelling
# usethis::use_spell_check()
Expand All @@ -137,6 +138,7 @@ aa
# _win devel
devtools::check_win_devel()
devtools::check_win_release()
devtools::check_mac_release()

# Check reverse dependencies
# remotes::install_github("r-lib/revdepcheck")
Expand All @@ -146,14 +148,17 @@ usethis::use_build_ignore("revdep/")
devtools::revdep()
library(revdepcheck)
# In another session
revdepcheck::revdep_todo()
# revdepcheck::revdep_add(packages = "fusen")
id <- rstudioapi::terminalExecute("Rscript -e 'revdepcheck::revdep_check(num_workers = 4)'")
rstudioapi::terminalKill(id)
# See outputs
revdep_details(revdep = "pkg")
revdep_summary() # table of results by package
revdep_details(revdep = "fusen")
revdep_summary()
# table of results by package
revdep_report() # in revdep/
# Clean up when on CRAN
revdep_reset()
revdepcheck::revdep_reset()

# Update NEWS
# Bump version manually and add list of changes
Expand Down
2 changes: 1 addition & 1 deletion man/att_from_rmds.Rd

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

41 changes: 41 additions & 0 deletions tests/testthat/escape_newline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This code contains knitr on a newline and should not be read with `\nknitr`

create_vignette_head <- function(pkg, vignette_name, yaml_options = NULL) {
pkgname <- basename(pkg)

# Get all yaml options except Title, output, editor_options
yaml_options <- yaml_options[
!names(yaml_options) %in% c("output", "title", "editor_options")]

enc2utf8(
glue(
'---
title: ".{vignette_name}."
output: rmarkdown::html_vignette',
ifelse(length(yaml_options) != 0,
glue::glue_collapse(
c("",
glue("{names(yaml_options)}: \"{yaml_options}\""), ""),
sep = "\n"),
"\n"),
'vignette: >
%\\VignetteIndexEntry{.{vignette_name}.}
%\\VignetteEngine{knitr::rmarkdown}
%\\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(.{pkgname}.)
```
',
.open = ".{", .close = "}."
)
)
}
47 changes: 47 additions & 0 deletions tests/testthat/quarto.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: "quarto demo"
date: "5/22/2021"
format:
html:
fig-width: 8
fig-height: 4
code-fold: true
---

## Air Quality

@fig-airquality further explores the impact of temperature on ozone level.

```{r}
#| label: fig-airquality
#| fig-cap: Temperature and ozone level.
#| warning: false
plot(pressure)
utils::packageVersion("knitr")
library("findme.quarto")
# library("dontfindme.quarto")
```

## Python should not be parsed

```{python}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```


File renamed without changes.
17 changes: 14 additions & 3 deletions tests/testthat/test-rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ all_to_be_found <- c(
"find.inline",
"bookdown",
"rmarkdown",
"emo"
"emo",
"findme.quarto",
"utils"
)

# One Rmd with YAML ---
Expand All @@ -29,7 +31,9 @@ test_that("rmd well parsed", {

# One output
res <- sort(attachment::att_from_rmd(path = "f1.Rmd"))
expect_equal(sort(res), sort(sort(setdiff(all_to_be_found, c("emo", "rmarkdown")))))
expect_equal(sort(res),
sort(sort(setdiff(
all_to_be_found, c("emo", "rmarkdown", "findme.quarto", "utils")))))
})

# A directory ----
Expand Down Expand Up @@ -57,4 +61,11 @@ test_that("test inside rmd works", {
}
})


# Test quarto and new way of chunk options with knitr>=1.35 ----
if (utils::packageVersion("knitr") >= "1.35") {
test_that("test inside qmd works", {
res <- attachment::att_from_rmds(path = ".")
expect_true("findme.quarto" %in% res)
expect_true(!"dontfindme.quarto" %in% res)
})
}
10 changes: 10 additions & 0 deletions tests/testthat/test-rscript.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,13 @@ test_that("att_from_rscripts well parsed", {
expect_false("base" %in% res_files)

})

# Test escape code not used ----
newline_script <- att_from_rscript(path = "escape_newline.R")

test_that("newline correctly escaped", {
expect_equal(sort(c("rmarkdown", "glue", "knitr")),
sort(newline_script))
expect_true(!"nknitr" %in% newline_script)

})
Loading

0 comments on commit 074a140

Please sign in to comment.