Skip to content

Commit

Permalink
expose path.type
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Jun 13, 2024
1 parent 4b25dcb commit f876c02
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
6 changes: 3 additions & 3 deletions R/table-notes.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' )
#'
#'@export
tab_notes <- function(notes, escape_fun = tab_escape,
tab_notes <- function(notes = character(0), escape_fun = tab_escape,
note_config = noteconf(type = "tpt"),
r_file = getOption("mrg.script", NULL),
r_file_label = "Source code: ",
Expand All @@ -42,7 +42,7 @@ tab_notes <- function(notes, escape_fun = tab_escape,
r_file_label, output_file_label,
path.type = path.type)

notes <- c(notes, file_info$notes)
notes <- c(notes, file_info$file_notes)

if(note_config$sanitize) {
assert_that(is.character(notes) || is.null(notes))
Expand Down Expand Up @@ -101,7 +101,7 @@ tab_files <- function(output_file, output_dir, r_file = NULL,
)

list(
notes = notes, # Notes entries for r and output files
file_notes = notes, # Notes entries for r and output files
r_file = r_file, # Name of the R file
output_file = output_file, # Full path to output file
output_note = output_note, # Output file, formatted
Expand Down
9 changes: 7 additions & 2 deletions R/table-object.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ st_arg_names <- c(
"sumrows", "note_config", "clear_reps", "clear_grouped_reps",
"hline_at", "hline_from", "sizes", "units", "drop",
"lt_cap_text", "lt_cap_macro", "lt_cap_label", "lt_cap_short", "lt_continue",
"caption",
"caption", "path.type",
"args"
)

Expand Down Expand Up @@ -491,6 +491,8 @@ st_right <- function(x,...) {
#' See the `r_file` and `output_file` arguments passed to [stable()] and then
#' to [tab_notes()].
#'
#' @inheritParams tab_notes
#'
#' @param x an stobject.
#' @param r set `r_file`, passed to [stable()].
#' @param output set `output_file`, the `.tex` file containing rendered
Expand All @@ -510,7 +512,7 @@ st_right <- function(x,...) {
#' @export
st_files <- function(x, r = getOption("mrg.script", NULL), output = NULL,
output_dir = getOption("pmtables.dir"),
esc = NULL) {
path.type = NULL, esc = NULL) {
check_st(x)
if(!missing(r)) {
if(!is.null(esc)) r <- tab_escape(r, esc = esc)
Expand All @@ -523,6 +525,9 @@ st_files <- function(x, r = getOption("mrg.script", NULL), output = NULL,
if(is.character(output_dir)) {
x$output_dir <- output_dir
}
if(is.character(path.type)) {
x$path.type <- path.type
}
x
}

Expand Down
43 changes: 43 additions & 0 deletions man/format_table_path.Rd

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

5 changes: 5 additions & 0 deletions man/st_files.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/tab_notes.Rd

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

18 changes: 16 additions & 2 deletions tests/testthat/test-table-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ test_that("option to format path - non project", {
expect_equal(x$output_note, file)
})

test_that("option to format path, path.type = proj", {
test_that("option to format path - path.type = proj", {
on.exit(options(pmtables.path.type = NULL, pmtables.dir = NULL), add = TRUE)
tdir <- tempfile("pmtables-test-") #normalizePath(tempdir(), "pmtables-test-")
fs::dir_create(tdir)
Expand Down Expand Up @@ -251,6 +251,21 @@ test_that("option to format path, path.type = proj", {
file.path(dir_proj, dir),
path.type = "proj"
), "tables/foo/bar.tex")

x <- pmtables:::tab_notes(
output_file = "bar.tex",
output_dir = "tables/foo",
path.type = "proj"
)
expect_equal(x$file_notes, "Source file: subdir/tables/foo/bar.tex")

options(pmtables.path.type = "proj")
y <- pmtables:::tab_notes(
output_file = "bar.tex",
output_dir = "tables/foo"
)
expect_equal(x$notes, y$notes)
options(pmtables.path.type = NULL)
})
})

Expand All @@ -263,4 +278,3 @@ test_that("table-utils paste units [PMT-TEST-0239]", {
c("B mg", "E", "D kg", "C pounds", "A")
)
})

0 comments on commit f876c02

Please sign in to comment.