gbRd/0000755000176200001440000000000014622071302011125 5ustar liggesusersgbRd/NAMESPACE0000644000176200001440000000044714621434042012354 0ustar liggesusersimportFrom(tools, Rd2txt, Rd2txt_options) export( Rd_args , Rd_fun , Rd_help2txt , Rd_name , Rd_title , Rdo_args2txt , Rdo_args2txt_list , Rdo_create , Rdo_empty , Rdo_get_arg , Rdo_get_args , Rdo_section , Rdo_set_sectag #, toolsdotdotdotfetchRdDB #, toolsdotdotdotRdTags ) gbRd/README.md0000644000176200001440000000061114621434042012405 0ustar liggesusersProvides utilities for processing Rd objects and files. Extract argument descriptions and other parts of the help pages of functions. `gbRd` is effectively superceded by `Rdpack`. However `gbRd` contains a call to an internal function related to parsing Rd files, which is not easy to copy, unless most of the Rd processing in package "utils" is copied, so Rdpack still imports it. gbRd/man/0000755000176200001440000000000014621434042011703 5ustar liggesusersgbRd/man/Rdo_args2txt_list.Rd0000644000176200001440000000304214621434042015606 0ustar liggesusers\name{Rdo_args2txt_list} \alias{Rdo_args2txt_list} \title{ Extract the descriptions of the arguments of a function } \description{ Collect the descriptions of the arguments of a function in a named list with one element per argument. } \usage{ Rdo_args2txt_list(x, arg, ...) } \arguments{ \item{x}{help object, may be any of the types that \code{\link{Rd_fun}} accepts: Rd object, name of a function, or the the value returned by \code{help}.} \item{arg}{ A character vector naming the arguments to describe. If \code{arg} is missing, descriptions of all arguments are extracted.} \item{\dots}{additional arguments to pass to \code{\link{Rdo_args2txt}}} } \details{ If several arguments are described in a single documentation entry, then the whole text of the entry is given for each of the arguments. } \value{ A named list with one entry (a string) for each of the requested arguments. } % \references{ % %% ~put references to the literature/web site here ~ % } % \author{ % %% ~~who you are~~ % } \author{Georgi N. Boshnakov} % \note{ % %% ~~further notes~~ % } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % \seealso{ \code{\link{Rdo_args2txt}} } \examples{ # each arg always gets an individual entry in the list; # compare: Rdo_args2txt_list("seq", c("from", "to", "by")) # to: cat(Rdo_args2txt("seq", c("from", "to", "by"))) } % % Add one or more standard keywords, see file 'KEYWORDS' in the % % R documentation directory. \keyword{ Rd } gbRd/man/gbRd-package.Rd0000644000176200001440000000107514621434042014444 0ustar liggesusers\name{gbRd-package} \alias{gbRd-package} \alias{gbRd} \docType{package} \title{ Utilities for processing Rd objects and files } \description{ Provides utilities for processing Rd objects and files. Extract argument descriptions and other parts of the help pages of functions. The main purpose of the functions is to facilitate extraction of descriptions of function arguments for presentation of simplified usage descriptions. } \author{ Georgi N. Boshnakov Maintainer: Georgi N. Boshnakov } \keyword{ package } gbRd/man/Rdo_section.Rd0000644000176200001440000000216014621434042014441 0ustar liggesusers\name{Rdo_section} \alias{Rdo_section} \title{ Extract a section element from an Rd object or Rd fragment } \description{ Extract a section element from an Rd object or Rd fragment. } \usage{ Rdo_section(rdo, sec) } \arguments{ \item{rdo}{an Rd object or fragment} \item{sec}{the required section, a string} } \details{ If the class or the "Rd_tag" attribute of \code{rdo} is "Rd" the required section is extracted. Otherwise, if this attribute is equal to \code{sec}, then \code{rdo} is returned. In all other cases it is assumed that \code{rdo} is the contents of the required section, its "Rd_tag" attribute is set to \code{sec} and returned without further modification. } \value{ An Rd fragment for use as a section element of an Rd object } \author{Georgi N. Boshnakov} \note{ This function is intended for use by other functions which work with Rd objects. } % \seealso{ % %% ~~objects to See Also as \code{\link{help}}, ~~~ % } % \examples{ % % } % % Add one or more standard keywords, see file 'KEYWORDS' in the % % R documentation directory. \keyword{ Rd } gbRd/man/Rdo_create.Rd0000644000176200001440000000233314621434042014242 0ustar liggesusers\title{ Create basic Rd objects } \name{Rdo_create} \alias{Rdo_create} \alias{Rdo_empty} \keyword{ Rd } \description{ Create basic Rd objects with fields title, name and arguments. } \usage{ Rdo_create(arguments, title = "Dummy title", name = "dummy name") Rdo_empty(rdtag) } \arguments{ \item{arguments}{The \code{argument} field of an Rd object} \item{title}{the title, a string} \item{name}{the name, atring} \item{rdtag}{a value for "Rd_tag", a string.} } \details{ \code{Rdo_create} is an auxiliary function used to prepare \code{arguments} for a call to \code{Rd_help2txt} since the latter works on Rd objects or text but not on Rd sections. \code{Rdo_empty} creates an empty object of class "Rd" if \code{rdtag} is missing. If \code{rdtag} is supplied the object is a list with attribute "Rd_tag" set to \code{rdtag}. } \value{ an Rd object or a list with attribute "Rd_tag". } \author{Georgi N. Boshnakov} \examples{ require(tools) # for Rd2txt a1 <- Rdo_get_args("seq") a1 Rdo_create(a1) Rd2txt(Rdo_create(a1)) a2 <- Rdo_get_args("seq", c("from", "to", "by")) a2 Rdo_create(a2) Rd2txt(Rdo_create(a2)) Rdo_empty() class(Rdo_empty()) str(Rdo_empty()) } gbRd/man/Rd_title.Rd0000644000176200001440000000267614621434042013753 0ustar liggesusers\name{Rd_title} \alias{Rd_title} \alias{Rd_name} \alias{Rd_args} \alias{Rdo_set_sectag} \title{ Wrap an object so that it can be used as a section element of an Rd object. } \description{ Wrap an object so that it can be used as a section element of an Rd object. } \usage{ Rdo_set_sectag(s,sectag,eltag) Rd_title(s) Rd_name(s) Rd_args(s) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{s}{the object to be wrapped, often a string, see Details} \item{sectag}{the section tag, a string} \item{eltag}{the element tag, a string} } \details{ \code{Rdo_set_sectag} sets atrribute "Rd_tag" of the object \code{s} to \code{eltag}, then wraps \code{s} in \code{list()} with "Rd_tag" attribute \code{sectag}. The remaining functions provide one-argument access for some frequently used special cases. \code{eltag} is "TEXT" for \code{Rd_title} and "VERB" for \code{Rd_name} and \code{Rd_args}. The values of \code{sectag} are \verb{\title}, \verb{\name} and \verb{\arguments}, respectively. } \value{ A tagged list as described in Details. } \author{Georgi N. Boshnakov} % \note{ % %% ~~further notes~~ % } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % % \seealso{ % %% ~~objects to See Also as \code{\link{help}}, ~~~ % } \examples{ Rd_title("My seq") Rd_name("myseq") "a" \%in\% letters # to do: more examples } \keyword{ Rd } gbRd/man/Rd_fun.Rd0000644000176200001440000000720114621434042013407 0ustar liggesusers\name{Rd_fun} \alias{Rd_fun} \title{ Return all or selected sections of a help topic as an Rd object } \description{ Return all or selected sections of a help topic as an Rd object. The help topic may be an Rd object, a character string (for the help function), or the value returned by the help function. } \usage{ Rd_fun(x, topic, pkgname = "", help_type = "text", verbose = FALSE, try.all.packages = FALSE, keep_section = TRUE) } %- maybe also 'usage' for other objects documented here. \arguments{ \item{x}{the help object. Its class may be "Rd", "character", or "help_files_with_topic".} \item{topic}{unused, see Details} \item{pkgname}{unused, see Details} \item{help_type}{type of help, see Details and \code{\link{help}}.} \item{verbose}{logical value, see \code{\link{help}}.} \item{try.all.packages}{logical value, see \code{\link{help}}.} \item{keep_section}{the section(s) to keep. If it is a character vector of length at least one, the sections listed in it (plus \verb{\title} and \verb{\name}) are kept in the result, the rest are dropped. Otherwise all sections are returned.} } \details{ If the class of \code{x} is neither "Rd" nor "help_files_with_topic", \code{x} is assumed to be appropriate for a call to \code{help}. The call is made to obtain an object of class "help_files_with_topic", which is then processed as below. Arguments \code{help_type}, \code{verbose} and \code{try.all.packages} are used only in this case. If the class of \code{x} is "help_files_with_topic" (usually the result of a call to \code{help}), then an Rd object is obtained using \code{tools:::fetchRdDB}. The Rd object (\code{x} itself or the one obtained as described above) is examined and sections are retained or dropped as specified by argument \code{keep_section}. Sections \verb{\title} and \verb{\name} are always kept in the returned value since otherwise the Rd object is considered invalid by (some of?) the system functions. } \value{ an Rd object } \author{Georgi N. Boshnakov} \note{ Note that \code{help} works with `installed' help. So, when the Rd object is obtained via a call to help it will not necessarilly be the one that would be obtained from the original Rd file if that contains \verb{\Sexpr} instructions with \code{stage=build} or \code{stage=install} optional argument. This is not a problem for the intended purpose of this package to allow for extraction of pieces of the help for selective display and related run-time actions. For manipulation of source Rd files one can supply an Rd object obtained by \code{parse_Rd}-ying it. FIXME: I wrote this function in a hurry when it turned out that the help system has changed in R version 2.10, needs clean up. todo: In recent versions of R, \code{help} may return more than one file (see \code{paths} in this function's source), this needs to be handled. } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % % \seealso{ % %% ~~objects to See Also as \code{\link{help}}, ~~~ % } \examples{ # 1st arg is name of a function Rd_fun("data.frame",keep_section="\\\\arguments") Rd_fun("seq",keep_section="\\\\arguments") # 1st arg is the value of a call to help() h1 <- help("seq") class(h1) Rd_fun(h1,keep_section="\\\\title") # note: in Rd file the number of Rd_fun(h1,keep_section="\\\\arguments") # backslashes is twice that in # the rendered doc. } % % Add one or more standard keywords, see file 'KEYWORDS' in the % % R documentation directory. \keyword{ Rd } gbRd/man/Rdo_args2txt.Rd0000644000176200001440000000311114621434042014550 0ustar liggesusers\name{Rdo_args2txt} \alias{Rdo_args2txt} \title{ Extract the descriptions of one or more arguments of a function } \description{ Extract help descriptions of one or more arguments of a function and return them as a string. } \usage{ Rdo_args2txt(rdo, arg, title = "Hhh", name = "Aa", type = "text") } \arguments{ \item{rdo}{the documentation for the topic, typically an Rd object but may be anything that \code{\link{Rd_fun}} accepts: Rd object, name of a function, or the value returned by \code{help}.} \item{arg}{name(s) of argument(s) to describe, a character vector, see also Details section} \item{title}{Title, a string} \item{name}{name, a string} \item{type}{type of the help, defaults to "text"} } \details{ The \code{title} and \code{name} fields are there, since descriptions of arguments usually do not use the same header as the description of the corresponding function. The current defaults show that this is still not finished. } \value{ A string (character vector of length one). } % \references{ % %% ~put references to the literature/web site here ~ % } \author{Georgi N. Boshnakov} % \author{ % %% ~~who you are~~ % } % \note{ % %% ~~further notes~~ % } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % \seealso{ \code{\link{Rdo_args2txt_list}} } \examples{ # ?seq cat(Rdo_args2txt("seq", c("by", "..."))) cat(Rdo_args2txt("seq", c("from", "by"))) } % % Add one or more standard keywords, see file 'KEYWORDS' in the % % R documentation directory. \keyword{ Rd } gbRd/man/Rdo_get_args.Rd0000644000176200001440000000471314621434042014576 0ustar liggesusers\name{Rdo_get_args} \alias{Rdo_get_args} \alias{Rdo_get_arg} \title{ Extract argument description from a help topic } \description{ Extract argument description from a help topic. } \usage{ Rdo_get_args(rd, args, ...) Rdo_get_arg(rd, arg) } \arguments{ \item{rd}{the documentation for the topic, typically an Rd object but may be anything that \code{\link{Rd_fun}} accepts.} \item{arg}{an argument name, a string} \item{args}{names of arguments to describe, a character vector, see also Details section} \item{\dots}{not used} } \details{ If \code{arguments} is missing, descriptions of all arguments are returned. Effort is made to handle the case when two or more arguments are described in a single entry. In that case it is not possible to disentangle the description automatically. So, the description is returned as is. Also, only one copy of the description is returned, see the examples with the \code{from} and \code{to} arguments of function \code{seq}. The \code{...} argument is handled, as well, give it as the string \verb{...} in \code{args}. \code{Rdo_get_arg} simply calls \code{Rdo_get_args} and returns the first element of its value. This means that \code{arg} is expected to be of length one, but this is not enforced. Note also that \code{Rdo_get_arg} is not completely equivalent to calling \code{Rdo_get_args} with \code{length(args)=1}. } \value{ For \code{Rdo_get_args}, an Rd fragment representing the (part of) help section \verb{\arguments} containing descriptions of the requested arguments. For \code{Rdo_get_arg} an Rd fragment representing the help for a single argument. } % \references{ % %% ~put references to the literature/web site here ~ % } % \author{ % %% ~~who you are~~ % } \author{Georgi N. Boshnakov} % \note{ % %% ~~further notes~~ % } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % % \seealso{ % %% ~~objects to See Also as \code{\link{help}}, ~~~ % } \examples{ h1 <- help("seq") Rdo_get_args(h1) Rdo_get_args(h1,"by") Rdo_get_args(h1,"length.out") Rdo_get_args(h1,"...") Rdo_get_args(h1,"from") Rdo_get_args(h1,c("from","by")) Rdo_get_args(h1,c("from", "to")) Rdo_get_args("seq") Rdo_get_args("seq","by") Rdo_get_args("seq","length.out") Rdo_get_args("seq","...") Rdo_get_args("seq","from") Rdo_get_args("seq",c("from","by")) Rdo_get_args("seq",c("from", "to")) } \keyword{ Rd } gbRd/man/Rd_help2txt.Rd0000644000176200001440000000553714621434042014403 0ustar liggesusers\name{Rd_help2txt} \alias{Rd_help2txt} %- Also NEED an '\alias' for EACH other topic documented here. \title{ Extract selected help sections as text. } \description{ Extract selected help sections as text. } \usage{ Rd_help2txt(x, topic, pkgname = "", help_type = "text", verbose = FALSE, try.all.packages = FALSE, keep_section = TRUE, omit_sec_header = FALSE) } \arguments{ \item{x}{the help object. Its class may be "Rd", string or "help_files_with_topic".} \item{topic}{passed on to \code{Rd_fun}} \item{pkgname}{passed on to \code{Rd_fun}} \item{help_type}{passed on to \code{Rd_fun}} \item{verbose}{passed on to \code{Rd_fun}} \item{try.all.packages}{passed on to \code{Rd_fun}} \item{keep_section}{the section to keep. If it is a character vector of length at least one, the sections listed in it (plus \verb{\title} and \verb{\name}) are kept in the result, the rest are dropped. Otherwise all sections are returned.} \item{omit_sec_header}{whether to omit or not the section header} } \details{ Basically, this function calls \code{Rd_fun} to get an Rd object containing the required help sections, then converts them to text with \code{tools::Rd2txt}. At this point however unwanted sections may be present since \code{tools::Rd2txt} requires \verb{\title} and \verb{\name}. If \verb{\title} is not an element of \code{keep_section}, it should be dropped. Other header information is dropped if \code{omit_sec_header = TRUE}. The way this is done is crude and based on inspection. It would be better done using the Rd object but then I might need to, effectively reprogram \code{Rd2txt}. FIXME: The above was done for version R-2.10 (I think), see if a more modular version is available in current versions of \R. Also, it is tested only with \code{help_type="text"}. FIXME: Arguments whose description is marked "passed on to \code{Rd_fun}" could be replaced by a "..." argument. } \value{ A character vector containing the text of the selected help sections. } % \references{ % %% ~put references to the literature/web site here ~ % } \author{Georgi N. Boshnakov} \note{ In R-2.12.0 the function \code{tools::Rd2txt} acquired a \code{fragment} argument. So, \code{tools::Rd2txt} now works with fragments and can be used directly in many cases. } % % %% ~Make other sections like Warning with \section{Warning }{....} ~ % % \seealso{ % %% ~~objects to See Also as \code{\link{help}}, ~~~ % } \examples{ # 1st arg is the name of a function Rd_help2txt("data.frame",keep_section="\\\\arguments") Rd_help2txt("seq",keep_section="\\\\examples") Rd_help2txt("seq",keep_section="\\\\examples",omit_sec_header=TRUE) } % % Add one or more standard keywords, see file 'KEYWORDS' in the % % R documentation directory. \keyword{ Rd } gbRd/DESCRIPTION0000644000176200001440000000154214622071302012635 0ustar liggesusersPackage: gbRd Type: Package Title: Utilities for Processing Rd Objects and Files Version: 0.4.12 Authors@R: c( person(given = c("Georgi", "N."), "Boshnakov", role = c("aut", "cre"), email = "georgi.boshnakov@manchester.ac.uk"), person("R Core Team", role = c("cph"), comment = "Extracted some non-exported functions from base R") ) Description: Provides utilities for processing Rd objects and files. Extract argument descriptions and other parts of the help pages of functions. Imports: tools License: GPL (>= 2) LazyLoad: yes NeedsCompilation: no Packaged: 2024-05-18 09:01:23 UTC; Georgi Author: Georgi N. Boshnakov [aut, cre], R Core Team [cph] (Extracted some non-exported functions from base R) Maintainer: Georgi N. Boshnakov Repository: CRAN Date/Publication: 2024-05-18 09:20:02 UTC gbRd/R/0000755000176200001440000000000014622067143011336 5ustar liggesusersgbRd/R/Rdutils.R0000644000176200001440000003021014621434042013076 0ustar liggesusers # See the help of Rd_db and the examples there! # "" also tools/R/Rd.R for other internal functions! # "" and RdConv2.R for utility functions. Rdo_empty <- function(rdtag){ # Create an empty Rdo; na 2011-11-22 dobavyam argument rdtag if(missing(rdtag)){ res <- list() class(res) <- "Rd" res }else structure(list(), Rd_tag = rdtag) } # Create a minimal Rdo. # todo: this is very basic, among other things, needs also empty lines. Rdo_create <- function(arguments, title="Dummy title", name="dummy name"){ res <- Rdo_empty() res[[1]] <- Rd_name(name) res[[2]] <- Rd_title(title) res[[3]] <- arguments res } # 2011-10-21 - bug fix - "Rd_tag is not set for Rd objects, their class attribute is "Rd" Rdo_section <- function(rdo, sec){ # 2011-10-30 - some clean up type <- attr( rdo, "Rd_tag") if(is.null(type)) type <- "" if(identical(class(rdo),"Rd") || type == "Rd"){ tags <- toolsdotdotdotRdTags(rdo) indx <- which(tags==sec) # todo: What to return when there are no matches? if(length(indx) > 1){ warning(paste("Found more than one section named", sec, ". Using only the first match.", sep="")) indx <- indx[1] } rdo[[which(tags==sec)]] }else if (type == sec) rdo else # assumes elements of rdo are elements of sec and wraps accordingly. structure(rdo, Rd_tag = sec) } Rdo_set_sectag <- function(s,sectag,eltag){ attr( s, "Rd_tag") <- eltag # using `structure' would be more elegant... res <- list(s) attr( res, "Rd_tag") <- sectag res } Rd_title <- function(s) Rdo_set_sectag(s, sectag="\\title" , eltag="TEXT") Rd_name <- function(s) Rdo_set_sectag(s, sectag="\\name" , eltag="VERB") Rd_args <- function(s) Rdo_set_sectag(s, sectag="\\arguments", eltag="VERB") Rdo_get_args <- function(rd,args,...){ # tools:::RdTags(rd[[which(tags=="\\arguments")]]) rdo <- Rd_fun(rd, # todo: argument ... is not used. , keep_section = "\\arguments" ) tags <- toolsdotdotdotRdTags(rdo) rdargs <- rdo[[which(tags=="\\arguments")]] # use of [[]] assumes only one element here # not a problem for installed documentation. # to do: Ako iskam da vklyucha obrabotka na prazni redove i drug text mezhdu # item-ite, obrabotkata ste se uslozhni. Tryabva i dopalnitelen argument! if(missing(args)) return(rdargs) # uslozhnyavam f, za da obrabotva i sluchai, kogato # nyakolko argumenta sa opisani v edin item. # f <- function(x){x[[1]] %in% args} f <- function(x){ # tozi code tryabva da se ischisti; dokato otkriya tazi rabota # (t.e. che e neobchodimo as.character) se omotach. wrk0 <- as.character(x[[1]]) # x[[1]] is tagged with Rd_tag or similar! if(wrk0 %in% args) return(TRUE) wrk <- strsplit(wrk0,",[ ]*") if(!is.character(wrk[[1]])){ warning("wrk[[1]] is not a character vector! ", wrk) return(FALSE) } wrk <- any( wrk[[1]] %in% args ) # ima li nuzhda ot trim na blanks? wrk } sel <- !sapply(rdargs, f) ## deal with "..." arg if("..." %in% args || "\\dots" %in% args){ # since formals() represents ... by "..." f2 <- function(x){ if(is.list(x[[1]]) && length(x[[1]])>0 && attr(x[[1]][[1]],"Rd_tag") == "\\dots") TRUE else FALSE } i2 <- sapply(rdargs, f2) sel[i2] <- FALSE } rdargs[sel] <- NULL # keeps attributes (even if 0 or 1 elem remain). rdargs } Rdo_get_arg <- function(rd,arg){ wrk <- Rdo_get_args(rd,arg) wrk[[1]] } Rdo_args2txt_list <- function(x,arg,...){ rdo <- Rd_fun(x) if(missing(arg)){ tmparg <- .Rd_get_argument_names(rdo) # tools:::.Rd_get_argument_names(rdo) # correct for merged descriptions... arg <- character(0) for(s in tmparg){ arg <- c(arg, strsplit( as.character(s), ",[ ]*")[[1]]) } } res <- list() for(a in arg) res[[a]] <- Rdo_args2txt(rdo,a,...) res } Rdo_args2txt <- function(rdo,arg,title="Hhh",name="Aa",type="text"){ wrk <- Rdo_get_args(rdo,arg) wrk2 <- Rdo_create(arguments=wrk,title=title,name=name) res <- Rd_help2txt(wrk2, keep_section = "\\arguments" , omit_sec_header = TRUE ) # nay-dobre e da ima programka, koyato da macha izlishni poleta! res <- paste(res,collapse="\n") res } # based on print.help_files_with_topic() in the sources of R-2.10.0. Rd_help2txt <- function(x, topic, pkgname="" , help_type="text" , verbose=FALSE , try.all.packages=FALSE , keep_section = TRUE , omit_sec_header = FALSE ){ rdo <- Rd_fun(x, topic=topic, pkgname=pkgname , help_type = help_type , verbose = verbose , try.all.packages = try.all.packages , keep_section = keep_section ) temp <- Rd2txt(rdo, out=tempfile("Rtxt"), package=pkgname) res <- readLines(temp) # note: temp is a (temporary) file name. unlink(temp) # krapka, iztrii title i/ili name ako ne sa poiskani. iomit <- numeric(0) # the code below assumes that each item is on one line followed by a blank line. if(!("\\title" %in% keep_section)) iomit <- c(iomit,1:2) # !!! Poleto "name" ne vliza v teksta, zatoca nyama nuzhda ot tova! # if(!("\\name" %in% keep_section)) # iomit <- c(iomit,3:4) if(isTRUE(omit_sec_header)) iomit <- c(iomit,3:4) # file.show(temp, title = gettextf("R Help on '%s'", topic), # delete.file = TRUE) if(length(iomit)>0) res <- res[-iomit] # !!! ??? MNOGO GRUBA KRAPKA za omit-vane na title/name res } # based on print.help_files_with_topic() in the sources of R-2.10.0. Rd_fun <- function(x, topic, pkgname = "" , help_type = "text" , verbose = FALSE , try.all.packages = FALSE , keep_section = TRUE ){ rdo <- NULL # prepare the "Rd" object rdo; # is it better to check with "inherit"? if(inherits(x, "Rd")){ # class(x) == "Rd" # if(inherits(file, "Rd")) ... rdo <- x }else{ if(!inherits(x, "help_files_with_topic")){ # class(x) != "help_files_with_topic" # The following comments baffle me now. Does `do.call' resolve the issues? # # help returns an object of class "help_files_with_topic" the # eval(substitute()) wrapper (I saw it in tkGUI, vzh sasto help.R, sasto: # .tryHelp in question.R) is needed to cover the case when x is a # function. Without this wrapper the result is not correct. # Izglezhda, che bez substitute() argumentat se evvaluate-va na nepodochodyasto # myasto. If x is a name of a function, then the wrapper is not needed. # wrk <- eval(substitute(help(x, help_type=help_type # , verbose=verbose # , try.all.packages=try.all.packages))) # cat("KUKUKUUUU: ", substitute(x), " class(x): ", class(x), "\n\n" ) wrk <- do.call("help",list(x, help_type=help_type , verbose=verbose , try.all.packages=try.all.packages)) x <- wrk } ## Check for errors! ??? if(inherits(x, "help_files_with_topic")){ # class(x) == "help_files_with_topic" # from print.help_files_with_topic in help.R # # browser <- getOption("browser") topic <- attr(x, "topic") type <- attr(x, "type") paths <- as.character(x) # removes attributes of x. # If more matches are found will `paths' have length > 1? file <- paths # !!! check for lenght(paths)==0 !!!! ?? # but no error is raized, rdo simply remain NULL. # the following commands are probably copied from utils:::.getHelpFile path <- dirname(file) dirpath <- dirname(path) pkgname <- basename(dirpath) RdDB <- file.path(path, pkgname) # cat("\n\nx is: " ,unclass(x) ,"\n\n\n") # cat("paths is: ",paths ,"\n") # cat("file is: ", file ,"\n") # cat("path is: ", path ,"\n") # cat("RdDB is: ", paste(RdDB, "rdx", sep="."),"\n") if(file.exists(paste(RdDB, "rdx", sep="."))) { rdo <- toolsdotdotdotfetchRdDB(RdDB, basename(file)) } } } if(is.null(rdo)) # todo: should someting less radical be done? stop("rdo object is NULL!") if(is.character(keep_section) && length(keep_section)>0){ tags <- toolsdotdotdotRdTags(rdo) keep_tags <- unique(c("\\title","\\name",keep_section)) rdo[which(!(tags %in% keep_tags))] <- NULL } rdo } # Rd2txt(wrk) # Rd2HTML(wrk) # 2011-10-30 premestvam v Rdpack funktsiite napisani sled publikuvane na originalnata # versiya na gbRd. ## 2013-11-28 the following are copied from 'tools' to avoid calling non-exported functions ## > tools:::RdTags toolsdotdotdotRdTags <- function (Rd) { res <- sapply(Rd, attr, "Rd_tag") if (!length(res)) res <- character() res } ## > tools:::fetchRdDB toolsdotdotdotfetchRdDB <- function (filebase, key = NULL) { fun <- function(db) { vals <- db$vals vars <- db$vars datafile <- db$datafile compressed <- db$compressed envhook <- db$envhook fetch <- function(key) lazyLoadDBfetch(vals[key][[1L]], datafile, compressed, envhook) if (length(key)) { if (!key %in% vars) stop(gettextf("No help on %s found in RdDB %s", sQuote(key), sQuote(filebase)), domain = NA) fetch(key) } else { res <- lapply(vars, fetch) names(res) <- vars res } } res <- lazyLoadDBexec(filebase, fun) if (length(key)) res else invisible(res) } .Rd_get_argument_names <- local({ f <- function(x,y) NULL function(x){ ## if(is.null(f)) if(length(formals(f)) > 1) f <<- utils::getFromNamespace(".Rd_get_argument_names", "tools") f(x) } }) gbRd/NEWS.md0000644000176200001440000000043414622067126012235 0ustar liggesusers# gbutils 0.4.12 - copied some functions from base R package 'tools' to avoid using `:::`. - minor tweaks of the code to remove NOTEs from R's checks (previous version, v0.4.11, of 'gbRd' was from 2012-10-01). - removed static package information from 'gbRd-package.Rd'. gbRd/MD50000644000176200001440000000127314622071302011440 0ustar liggesusers27d6aeaa1738c9cce52afc218320eb87 *DESCRIPTION a6162e8acf74bf62da14f639c81c74a5 *NAMESPACE 7e7adbdc5d03a0c4f188793eb758139d *NEWS.md 64fa7cb6e934c26520565d3fc160bb4d *R/Rdutils.R b2ccba6a679b12a1a1df0c8362a1df3c *README.md 2f17e683ad7f2f093a843a1ff2696d34 *man/Rd_fun.Rd 16bbe425d3728e98a79bcd409254d634 *man/Rd_help2txt.Rd abebeaa25e59c35dc693c1e65209ba92 *man/Rd_title.Rd ce3f9f5efcf76fb70f7df4cd55c9e0c8 *man/Rdo_args2txt.Rd 185fa945bbeb2dde103ed6e56addc2b2 *man/Rdo_args2txt_list.Rd 393d3a37bdf828c13b096747f2eb2eb5 *man/Rdo_create.Rd 41d4c934b18a5b7993d65b47ba046b0a *man/Rdo_get_args.Rd 70c602f8781979e2f3e6aa02effc2aa4 *man/Rdo_section.Rd 514347d2a4359a999ea02e6297530fee *man/gbRd-package.Rd