Skip to content
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

Incorporate reasonable changes to some of the R files within R/ #38

Merged
merged 12 commits into from
Jul 7, 2021
Merged
69 changes: 32 additions & 37 deletions R/doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ dldoc <- function # Make directlabels documentation
### we can automatically assemble a database of example plots from the
### code.
(pkgdir=".."
### Package directory root.
){
### Package directory root.
){
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved
odir <- setwd(pkgdir)
on.exit(setwd(odir))
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved
docdir <- file.path("tests","doc")
docdirs <- dir(docdir)
plotfiles <- sapply(docdirs,function(d)Sys.glob(file.path(docdir,d,"*.R")))
Expand Down Expand Up @@ -47,14 +46,12 @@ dldoc <- function # Make directlabels documentation
makerd <- function # Make Rd positioning method description
(L
## List of posfuns and plots to match up
){
){
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved

plotcodes <-
paste("{\n",sapply(L$plots,"[[","code"),"\n}",sep="",collapse=",\n")
plotcodes <- paste("{\n",sapply(L$plots,"[[","code"),"\n}",sep="",collapse=",\n")
forloop <- paste("\nfor(p in list(",plotcodes,"))",sep="")
dlines <-
paste(paste('print(direct.label(p,"',
names(L$posfuns),'"))',sep=""),collapse="\n ")
dlines <- paste(paste('print(direct.label(p,"',
names(L$posfuns),'"))',sep=""),collapse="\n ")
sprintf("### %s Positioning Methods%s{\n %s\n}\n",L$type,forloop,dlines)
}
rd <- apply(m[rownames(m)!="utility.function",],1,makerd)
Expand All @@ -75,18 +72,17 @@ dldoc <- function # Make directlabels documentation
version <- read.dcf("DESCRIPTION")[,"Version"]
git.line <- system('git log -1 --pretty=format:"%h %aD"', intern=TRUE)
foot.info <- list(version=version,git=as.character(git.line))
setwd(file.path("..","..","www","docs"))
foot <- filltemplate(foot.info,"templates/foot.html")
foot <- filltemplate(foot.info,"docs/templates/foot.html")
makehtml <- function # Make HTML documentation
## Make plots and HTML for documentation website.
(L
## List of positioning method and plots to match up.
){
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved
){
## all paths are relative to the docs directory
subdir <- L$type
subdir <- file.path("docs",L$type)
pngurls <- matrix("",nrow=length(L$posfuns),ncol=length(L$plots),
dimnames=list(names(L$posfuns),
sapply(L$plots,function(x)x$name)))
sapply(L$plots,function(x)x$name)))
## first make plots
datanames <- names(L)[sapply(L,class)=="list"]
tomake <- file.path(subdir,c("",datanames))
Expand Down Expand Up @@ -128,15 +124,15 @@ dldoc <- function # Make directlabels documentation
parname=item$name,
url=file.path("..",row,paste(f$name,".html",sep="")))
})
rowfile <- paste("templates/",row,"-row.html",sep="")
rowfile <- paste("docs/templates/",row,"-row.html",sep="")
rowhtml <- sapply(tmp,filltemplate,rowfile)
item$table <- paste(c("<table>",rowhtml,"</table>"),collapse="\n")
}
item$type <- L$type
item$pagetitle <- item$name
item$head <- filltemplate(item,"templates/head.html")
item$head <- filltemplate(item,"docs/templates/head.html")
item$foot <- foot
html <- filltemplate(item,paste("templates/",main,".html",sep=""))
html <- filltemplate(item,paste("docs/templates/",main,".html",sep=""))
write(html,file.path(subdir,main,paste(item$name,".html",sep="")))
item
}
Expand Down Expand Up @@ -165,26 +161,26 @@ dldoc <- function # Make directlabels documentation
},simplify=FALSE)
}
links <- apply(m,1,extract.links)
tmp <- list(head=filltemplate(list(pagetitle="home"),"templates/head.html"),
tmp <- list(head=filltemplate(list(pagetitle="home"),"docs/templates/head.html"),
foot=foot)
rows <- lapply(links,filltemplate,"templates/index-row.html")
rows <- lapply(links,filltemplate,"docs/templates/index-row.html")
tmp$table <- paste(rows,collapse="\n")
html <- filltemplate(tmp,"templates/index.html")
write(html,"index.html")
html <- filltemplate(tmp,"docs/templates/index.html")
write(html,"docs/index.html")

m
### Matrix of lists describing example plots and matching builtin
### Positioning Methods.
### Matrix of lists describing example plots and matching builtin
### Positioning Methods.
}

extract.posfun <- function # Extract Positioning Method for documentation
### Use inlinedocs to extract comments and definitions from code, then
### for each item found add the value and its name to the list.
(f
### R code file, which should contain only Positioning Methods that
### can be used with examples defined in the doc/ subdirectory with
### the same name.
){
### R code file, which should contain only Positioning Methods that
### can be used with examples defined in the doc/ subdirectory with
### the same name.
){
L <- inlinedocs::extract.docs.file(f)
e <- new.env()
sys.source(f,e)
Expand All @@ -197,16 +193,16 @@ extract.posfun <- function # Extract Positioning Method for documentation
## otherwise if one function's name is a substring of another's!
##L <- L[order(nchar(names(L)),decreasing=TRUE)]
L
### List of lists, each of which describes one Positioning Method
### defined in f.
### List of lists, each of which describes one Positioning Method
### defined in f.
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved
}

extract.plot <- function # Extract plot and definition for documentation
### Given an R code file, execute it, store the definition, and save
### the resulting plot in a variable.
(f
### R code file with plot example.
){
### R code file with plot example.
){
require(directlabels)
code <- readLines(f)
i <- max(grep("^\\w",code))
Expand All @@ -223,12 +219,12 @@ extract.plot <- function # Extract plot and definition for documentation
rhtmlescape <- function
### for standards compliance we should escape <>&
(code
### R code to be displayed on a HTML page between pre tags.
){
### R code to be displayed on a HTML page between pre tags.
){
code <- gsub("[&]","&amp;",code)
code <- gsub("[<]","&lt;",code)
code <- gsub("[>]","&gt;",code)
### Standards compliant HTML to display.
### Standards compliant HTML to display.
}

filltemplate <- function
Expand All @@ -239,13 +235,12 @@ filltemplate <- function
L <- L[sapply(L,class)=="character"&sapply(L,length)>0]
locs <- gregexpr("OBJ[$]([a-z]+)\\b",txt)[[1]]
keywords <- sapply(seq_along(locs),function(i)
substr(txt,locs[i]+4,locs[i]+
attr(locs,"match.length")[i]-1))
substr(txt,locs[i]+4,locs[i]+
attr(locs,"match.length")[i]-1))
FIND <- sapply(keywords,function(x)paste("OBJ[$]",x,sep=""))
REP <- unlist(ifelse(keywords%in%names(L),L[keywords],""))
for(i in seq_along(FIND)){
txt <- gsub(FIND[i],REP[i],txt)
}
txt
}

4 changes: 2 additions & 2 deletions R/positioning.functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dlgrob <- function
axes2native=identity,
...
){
## increment dlgrob.id to get a unique name because as explaine on
## increment dlgrob.id to get a unique name because as explained on
## ?grid::gTree "Grob names need not be unique in general, but all
## children of a gTree must have different names."
dl.env$dlgrob.id <- dl.env$dlgrob.id+1L
Expand Down Expand Up @@ -147,7 +147,7 @@ direct.label <- structure(function # Direct labels for color decoding
print(direct.label(ratplot))
## To put them on the same side, just manually specify the
## Positioning Method.
print(direct.label(ratplot,"last.qp"))
Anirban166 marked this conversation as resolved.
Show resolved Hide resolved
print(direct.label(ratplot,"last.qp"))

lattice.options(oldopt)
})
Expand Down