Skip to content

Commit

Permalink
fix issue #37
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoBosh committed Nov 15, 2024
1 parent a629201 commit 94753bf
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: Rdpack
Type: Package
Title: Update and Manipulate Rd Documentation Objects
Version: 2.6.1.9000
Version: 2.6.2.9000
Authors@R: c( person(given = c("Georgi", "N."),
family = "Boshnakov",
role = c("aut", "cre"),
Expand Down
22 changes: 19 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
# Rdpack 2.6.1.9000
# Rdpack 2.6.2

- `RStudio_reprompt' now issues a more informative error message when not called on a
suitable file or function. Fixes issue #30 by @daattali.
- changed the condition in the test fixing the issue in Rdpack v2.6.1 to
`getRversion() < "4.5.0"`, which is less likely to need further change for
R-4.4.x releases.



# Rdpack 2.6.2

- `RStudio_reprompt` now issues a more informative error message when not called
on a suitable file or function. Fixes issue #30, reported by @daattali.

- now the LaTeX macro `\slash` is wrapped in a condition, so that it is passed
on for LaTeX related output but converted to `/` for other formats (such as
html). Fixes GeoBosh/rbibutils#9, reported by @MLopez-Ibanez.

- fixed the test for the fix in Rdpack v2.6.1 (see below) to work with R-4.4.2,
since that R-devel change was not carried on to R-4.4.2. (Note: the error
concerns the test only. The fix in the code of the package works for any R
version.) Fixes issue #37, reported by @charles-plessy.


# Rdpack 2.6.1

- R-devel c86938 turned to error the warning for a non-existing key in the bib
Expand Down
69 changes: 35 additions & 34 deletions R/RStudio.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,40 @@ RStudio_reprompt <- function(verbose = TRUE) {
infile <- sourceContext$path

if(length(infile) == 0)
stop("Nothing to do. See ?Rdpack::RStudio_reprompt")

if (grepl("[.][rR]d$", infile)) # editing a help file
reprompt(infile = infile, filename = infile, verbose = verbose)

else if (grepl("[.][rRsSq]$", infile)) { # editing R source
pkgdir <- rprojroot::find_package_root_file(path = dirname(infile))
pkg <- basename(pkgdir)

if (length(sourceContext$selection) == 1) {
fnname <- sourceContext$selection[[1]]$text
stop("Nothing to do. See ?Rdpack::RStudio_reprompt for information about this add-in.")

if (grepl("[.][rR]d$", infile)) # editing a help file
reprompt(infile = infile, filename = infile, verbose = verbose)

else if (grepl("[.][rRsSq]$", infile)) { # editing R source
pkgdir <- rprojroot::find_package_root_file(path = dirname(infile))
pkg <- basename(pkgdir)

if (length(sourceContext$selection) == 1) {
fnname <- sourceContext$selection[[1]]$text
} else
fnname <- ""
if (!nchar(fnname))
stop("Select a function name")

if (!exists(fnname))
stop("Object ", sQuote(fnname), " not found. Run 'Install and Restart'?")

existing <- help(fnname)
## Subset to the ones in the current package
existing <- existing[basename(dirname(dirname(existing))) == pkg]

if (length(existing) == 1) {
infile <- file.path(pkgdir, "man", paste0(basename(existing), ".Rd"))
reprompt(infile = infile, filename = infile, verbose = verbose)
} else if (!length(existing))
infile <- reprompt(fnname,
filename = file.path(pkgdir, "man", paste0(fnname, ".Rd")),
verbose = verbose)
else
stop("Multiple matches to ", sQuote(fnname), ". Open one help file manually.")
} else
fnname <- ""
if (!nchar(fnname))
stop("Select a function name")

if (!exists(fnname))
stop("Object ", sQuote(fnname), " not found. Run 'Install and Restart'?")

existing <- help(fnname)
# Subset to the ones in the current package
existing <- existing[basename(dirname(dirname(existing))) == pkg]

if (length(existing) == 1) {
infile <- file.path(pkgdir, "man", paste0(basename(existing), ".Rd"))
reprompt(infile = infile, filename = infile, verbose = verbose)
} else if (!length(existing))
infile <- reprompt(fnname, filename = file.path(pkgdir, "man", paste0(fnname, ".Rd")),
verbose = verbose)
else
stop("Multiple matches to ", sQuote(fnname), ". Open one help file manually.")
} else
stop("This tool only works on .Rd or .R files.")

rstudioapi::navigateToFile(infile)
stop("This tool only works on .Rd or .R files.")

rstudioapi::navigateToFile(infile)
}
5 changes: 5 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* (2024-11-09) do something with 'RdpackTester' (under inst/examples).
I had forgotten about it but could add examples about issues and their fixing.
Also, indicate somewhere to users how to use it to report bugs.
Alternatively, make a repo where they can contribute.

* vignette for reprompt/ereprompt/RStudio_reprompt

* pcDst.Rd gives an error, it was produced by Roxygen.
Expand Down
2 changes: 1 addition & 1 deletion man/RStudio_reprompt.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ it will try to create one.
Duncan Murdoch
}
\seealso{
\code{\link{reprompt}}, \code{\link{prompt}}
\code{\link{reprompt}}, \code{\link{ereprompt}}, \code{\link{prompt}}
}
2 changes: 1 addition & 1 deletion tests/testthat/test-bib.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test_that("bib works fine", {
insert_ref("Rpackage:Rdpack", package = "rbibutils")

## missing keys
if(getRversion() <= "4.4.1")
if(getRversion() < "4.5.0")
expect_warning(insert_ref("xxx", package = "rbibutils"))
else # since R-devel c86938 the warning was changed to error
expect_error(insert_ref("xxx", package = "rbibutils"))
Expand Down

0 comments on commit 94753bf

Please sign in to comment.