-
Notifications
You must be signed in to change notification settings - Fork 3
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
User-defined macros needed to re-parse transformed Rd source #28
Comments
Thanks for the report. Yes, macros are a problem. I'm not super familiar with how they work since I never used them. If I understood you correctly. By passing macro definition, when parsing the Rd file they are evaluated, which means that the translated text won't have them? Ideally, we would need to keep the macros as they are in the translated text so they can be translated (if necessary) and then translated. |
Added support for parsing custom macros. However, these are not evaluated after translation, so the result is a mess. I think the most robust way to support this would be to preserve the macro in the translated text and the re-parse the Rd file after translation. The problem is that |
Looks like you've successfully expanded the macros and are now being bitten by #25: too late to evaluate Preserving unexpanded macros in the translatable source may be impossible with There might be a way to manually deparse unexpanded macros from the returned parse tree, because the body of the macro and its arguments are preserved there: r"{\newcommand{\foo}{aaaaaaaaaaaa \eqn{#1} aaaaaaaaaaaaaaa}\foo{1}bbbbbbbbb}" |>
textConnection(name = 'foo') |>
tools::parse_Rd(fragment = TRUE) -> foo
foo[[2]] # the unevaluated macro is preserved together with the arguments
# [1] "aaaaaaaaaaaa \\eqn{#1} aaaaaaaaaaaaaaa" "1"
# attr(,"Rd_tag")
# [1] "USERMACRO"
# attr(,"macro")
[1] "\\foo" ...but then you'll have to separate them from the results of their expansion, which is hard: foo[[5]] # macro expansion concatenated with the following text
# [1] " aaaaaaaaaaaaaaabbbbbbbbb\n"
# attr(,"Rd_tag")
# [1] "TEXT" Even terrible stuff like |
Consider a package that uses user-defined macros in the Rd source. In order to parse the documentation successfully, you have to give the right
macros
argument toparse_Rd
. It must contain just enough state, including the pre-defined R macros, package's own macros fromman/macros/*.Rd
, and any of the package dependencies declared in theRdMacros
field of theDESCRIPTION
file.tools::loadPkgRdMacros
should do the trick for a package source directory or an installed package directory inside a library.Without the macros, either
make_text
orto_text
eventually fails:Once you provide the macro definitions correctly, they will not show up in the deparsed Rd text:
This may or may not become a problem when translating. (Most interesting macros expand to
\Sexpr[stage=build]{...}
.)Edit: I'm sorry, but I seem to be followed by virus-spreading spammers. Please block and report them on sight.
The text was updated successfully, but these errors were encountered: