|
38 | 38 | sub("\\s+$", "", formatted) |
39 | 39 | } |
40 | 40 |
|
| 41 | +.iscam_rd_to_lines <- function(rd) { |
| 42 | + tmp <- tempfile(fileext = ".txt") |
| 43 | + on.exit(unlink(tmp), add = TRUE) |
| 44 | + tools::Rd2txt(rd, out = tmp) |
| 45 | + readLines(tmp, warn = FALSE) |
| 46 | +} |
| 47 | + |
41 | 48 | .iscam_show_help <- function(topic) { |
42 | 49 | pkg_man <- system.file("man", package = "ISCAM") |
43 | 50 | pkg_rd <- if (nzchar(pkg_man)) { |
|
46 | 53 | "" |
47 | 54 | } |
48 | 55 | if (nzchar(pkg_rd) && file.exists(pkg_rd)) { |
49 | | - capture.output(tools::Rd2txt(pkg_rd, out = "")) |> |
| 56 | + .iscam_rd_to_lines(pkg_rd) |> |
50 | 57 | .iscam_format_help() |> |
51 | 58 | paste(collapse = "\n") |> |
52 | 59 | cat("\n", sep = "") |
|
68 | 75 | rd_path <- rd_paths[1] |
69 | 76 |
|
70 | 77 | if (!is.na(rd_path) && nzchar(rd_path)) { |
71 | | - capture.output(tools::Rd2txt(rd_path, out = "")) |> |
| 78 | + .iscam_rd_to_lines(rd_path) |> |
72 | 79 | .iscam_format_help() |> |
73 | 80 | paste(collapse = "\n") |> |
74 | 81 | cat("\n", sep = "") |
|
81 | 88 | return(invisible(FALSE)) |
82 | 89 | } |
83 | 90 |
|
84 | | - utils:::.getHelpFile(help_obj) |> |
85 | | - tools::Rd2txt(out = "") |> |
86 | | - capture.output() |> |
| 91 | + rd_db <- tools::Rd_db("ISCAM") |
| 92 | + rd_key <- c(paste0(topic, ".Rd"), topic) |> |
| 93 | + intersect(names(rd_db)) |
| 94 | + |
| 95 | + if (length(rd_key) == 0) { |
| 96 | + cat("No documentation available for", topic, "\n") |
| 97 | + return(invisible(FALSE)) |
| 98 | + } |
| 99 | + |
| 100 | + rd_db[[rd_key[1]]] |> |
| 101 | + .iscam_rd_to_lines() |> |
87 | 102 | .iscam_format_help() |> |
88 | 103 | paste(collapse = "\n") |> |
89 | 104 | cat("\n", sep = "") |
|
0 commit comments