Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix help on Windows #224

Merged
merged 8 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
/pkgdown/favicon/
/src/*.o
/src/*.so
/src/*.dll
/vignettes/*.html
/vignettes/*.R
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# box (development version)

* Fix: make interactive HTML module help work on Windows (#223)
* Fix: prevent segfault in R ≤ 3.6.1 caused by missing declaration of internal R
symbol (#213)
* Fix: Allow exporting modules that were previously imported using a different
Expand Down
17 changes: 10 additions & 7 deletions R/display-help.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ compile_help.text_help_format = function (x, rd) {
}

compile_help.html_help_format = function (x, rd) {
tools::Rd2HTML(rd, out = tempfile('Rtxt'), package = mock_package_name)
tools::Rd2HTML(rd, out = tempfile('Rtxt'), package = c(mock_package_name, NA_character_))
}

patch_topic_name.text_help_format = function (x, file, topic) {
Expand All @@ -28,21 +28,24 @@ patch_topic_name.text_help_format = function (x, file, topic) {
}

patch_topic_name.html_help_format = function (x, file, topic) {
topic = gsub('"', '"',
gsub('<', '&gt;',
gsub('<', '&lt;',
gsub('&', '&amp;', topic))))
from = c('&', '<', '>', '"')
to = c('&amp;', '&lt;', '&gt;', '&quot;')
replace = data.frame(rbind(from, to))
topic = Reduce(function (x, r) gsub(r[1L], r[2L], x), replace, topic)
doc_text = readLines(file)
doc_text = gsub(mock_package_name, topic, doc_text)
writeLines(doc_text, file)
}

display_help_file.text_help_format = function (x, file, topic) {
file.show(file, title = gettextf('R Help on %s', dQuote(topic)),
delete.file = TRUE)
file.show(
file, title = gettextf('R Help on %s', dQuote(topic)),
delete.file = TRUE
)
}

display_help_file.html_help_format = function (x, file, topic) {
topic = sanitize_path(topic)
port = tools::startDynamicHelp(NA)
html_path = file.path(tempdir(), sprintf('.R/doc/html/%s.html', topic))
dir.create(dirname(html_path), recursive = TRUE, showWarnings = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/help.r
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ help = function (topic, help_type = getOption('help_type', 'text')) {
}
}

display_help(doc, paste0('module:', mod_name), help_type)
display_help(doc, mod_name, help_type)
}

#' Parse a module’s documentation
Expand Down
8 changes: 8 additions & 0 deletions R/paths.r
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ split_path = function (path) {
merge_path = function (components) {
do.call('file.path', as.list(components))
}

#' \code{sanitize_path(path)} replaces invalid characters in the given
#' \emph{relative} path, making the result a valid Windows path.
#' @rdname paths
sanitize_path = function (path) {
win32_reserved_path_chars = '[<>:"/\\|?*]'
gsub(win32_reserved_path_chars, '_', path)
}
2 changes: 1 addition & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ navbar:
- text: Migration guide for version 1.0
href: articles/migration.html
- text: Similar packages
href: articles/more.html
href: articles/related.html
- text: ---
- text: Implementation details
- text: The hierarchy of module environments
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-basic.r
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test_that('legacy function warning can be silenced', {
expect_warning(box::use(mod/legacy/require), NA)

expect_false(exists('source_test', envir = .GlobalEnv))
on.exit(rm(source_test, envir = .GlobalEnv))
on.exit(rm(source_test, envir = .GlobalEnv), add = TRUE)
expect_warning(box::use(mod/legacy/source), NA)
expect_true(exists('source_test', envir = .GlobalEnv))
})
Expand Down
19 changes: 9 additions & 10 deletions vignettes/more.rmd → vignettes/related.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

The need for tools that make R code more modular and improve code reuse is
The need for tools to make R code more modular, and to improve code reuse, is
demonstrated by the wealth of related packages that have sprung up over the
years. Many of them have goals similar to ‘box’, although they differ wildly in
how they approach this common goal, and not all goals are shared. I won’t
compare them all here, since I’m afraid I might not do them justice. The
following list, along with the descriptions (mostly) copied from the package
metadata, shall therefore stand on its own, and the interested reader is invited
to consult the original documentation.

The following is intended to be a fairly exhaustive list — so if you know of a
missing package, please let me know.
years. Many of them have objectives similar to ‘box’, although they vary wildly
in how they approach their common goal, and not all objectives are shared. In
the following I’ve listed the related R packages that I know of. The
descriptions are (mostly) copied from the respective package metadata, and the
interested reader is invited to consult the original documentation.

The list is intended to be a fairly exhaustive — so if you find a missing
package please let me know.

## Tools for writing modular code

Expand Down