[R-pkg-devel] line justification for long \code{} in .pdf manual
Fernando Roa
|ro@o @end|ng |rom un@|@edu@co
Thu Jun 4 20:52:50 CEST 2020
I notice the CRAN pdf didn't justify correctly long texts inside \code{}
even having "," or spaces irrespective of the status of the argument
(oneliner or multiliner)
in source (.R / .Rd)
https://imgur.com/RvjzMDh
I noticed also that it is not a problem in a pkgdown doc:
https://imgur.com/LsmuPE1
I ended up splitting the \code{} into several \codes{} with
file.R with \code{...} in one line as input.
example
from:
\code{unique(c(dfMarkPos$markName,dfCenMarks$markName) ) }
to:
\code{unique(c(dfMarkPos$markName,} \code{dfCenMarks$markName) ) }
https://imgur.com/Pwhfu0j
I used roxygen formatted .R, but could work with .Rd
after .R script (below) I produced .Rd with devtools:document(), then,
pdf: devtools::build_manual(path=getwd())
gblines<-readLines(file)
for (i in 1:length(gblines) ) {
if(grepl("^#\'",gblines[i]) & grepl("\\code",gblines[i] ) ) {
co <- regmatches(gblines[i], gregexpr('code\\{.*?\\}', gblines[i],
perl=T) )
if(length(co[[1]])>0){
co2 <- strsplit(co[[1]],",")
withCode <- unlist(lapply(co2, function(x) unlist(regmatches(x,
gregexpr('code\\{.*', x, perl=T) ) ) ) )
notWithCode <- (lapply(co2, function(x) unlist(regmatches(x,
gregexpr('^(?:(?!code\\{.*).)*$', x, perl=T) ) ) ) )
names(notWithCode)<-1:length(notWithCode)
names(withCode)<-1:length(withCode)
l_tmp <- c(withCode, notWithCode)
keys = unique(names(l_tmp))
l = sapply(keys, function(name) {unlist(l_tmp[grep(name,
names(l_tmp))])}, simplify = F)
repwith<-list(unlist(lapply(l, function(x) paste(x, collapse=",}
\\code{"))
) )
regmatches(gblines[i], gregexpr('code\\{.*?\\}', gblines[i], perl=T)
) <-repwith
}
}
}
writeLines(gblines, file)
best,
--
Fernando Roa
[[alternative HTML version deleted]]
More information about the R-package-devel
mailing list