+ Show code- Hide code
# This is code Op_en7457/fill on page [[Branch creator]]
# Parameters:
## newpage: TRUE if a new page is being created
## newdata: TRUE if a new data-based (from t2b) ovariable is being created
## newformula: TRUE if a new formula-based ovariable is being created
## branchname: name of the branch
## output.ovariable: name of the ovariable that calculates the final output of this branch. The name is used in the Answer code.
## data.ovariable: name of an ovariable that takes data as input
## t2bdata: table of data to be converted in the data slot of the variable
## data.rationale: textbox of description for data.ovariable
## formula.ovariable: name of an ovariable based on formula and dependencies
## dependencies: character vector of the names of dependencies
## formula: the body of the formula (should contain the function 'return' in the end)
## formula.rationale: textbox of description for formula.ovariable
library(OpasnetUtils)
t2bdata <- ""
#wiki_username <- "Jouni"
#branchname <- "Garden tower branch"
#PAGEID <- "1234"
#formula.ovariable <- "gardentower"
#data.ovariable <- "vegeproduction"
#dependencies <- c("vegeproduction", "wasteproduction", "waterconsumption")
#formula.rationale <- "Garden tower composts kitchen waste and turns it into soil."
#data.rationale <- "vegeproduction is the amount of vegetables produced in the garden tower. It is a critical benefit that reduces consumption of other products and thus footprint."
#<t2b name='Tire inflation parameters' index='Parameter,Unit' obs='Result' unit='-'>
#Pressure drop per temperature drop|PSI /10°F|0.5:1:2
#Fuel economy sensitivity|% /PSI|0.4
#Miles driven per year|mi /a|10000
#Fuel consumption|gl /mi|0.04
#Pressure deficit|PSI|2
#</t2b>
if(newpage) {
newpage <- paste("[[Category:Life cycle assessment]]
[[Category:Handprinter]]
{{method|moderator=",
wiki_username,
"}}
",
"'''{{PAGENAME}}''' is a '''branch''' of Handprinter. This page is a test case how to manage branches.
== Question ==
How to estimate the life-cycle impacts of '''{{PAGENAME}}'''?
== Answer ==
¤rcode embed=1 variables='
name:PAGEID|type:hidden|default:{{PAGEID}}
'>
# This is code Op_enXXXX/ on page [[",
branchname,
"]]
library(OpasnetUtils)
objects.latest(paste('Op_en', PAGEID, sep = ''), code_name = '",
output.ovariable,
"')
",
output.ovariable,
" <- EvalOutput(",
output.ovariable,
")
oprint(summary(",
output.ovariable,
"))
¤/rcode>
== Rationale ==
",
sep = ""
)
}
if(newdata) {
newdata <- paste(
"=== ",
data.ovariable,
" ===
",
t2bdata,
"¤rcode name='",
data.ovariable,
"' embed=1 label='Initiate ",
data.ovariable,
" (for developers only)' variables='
name:PAGEID|type:hidden|default:{{PAGEID}}
'>
# This is code Op_enXXXX/",
data.ovariable,
" on page [[",
branchname,
"]]
library(OpasnetUtils)
",
data.ovariable,
" <- Ovariable('",
data.ovariable,
"',
ddata = paste('Op_en', PAGEID, sep = ''),
subset = '",
data.ovariable,
"')
objects.store(",
data.ovariable,
")
cat('Object',",
data.ovariable,
"@name, 'stored.@@')
",
"¤/rcode>
",
data.rationale,
"
",
sep = ""
)
}
if(newformula) {
newformula <- paste(
"=== ",
formula.ovariable,
" ===
¤rcode name='",
formula.ovariable,
"' embed=1 label='Initiate ",
formula.ovariable,
" (for developers only)'>
# This is code Op_enXXXX/",
formula.ovariable,
" on page [[",
branchname,
"]]
library(OpasnetUtils)
",
formula.ovariable,
" <- Ovariable('",
formula.ovariable,
"',
dependencies = data.frame(
Name = c('",
paste(dependencies, collapse = "', '"),
"')
),
formula = function(...) {
",
formula,
" }
)
objects.store(",
formula.ovariable,
")
cat('Object ',",
formula.ovariable,
"@name, ' stored.@@')
¤/rcode>
",
formula.rationale,
"
",
sep = ""
)
}
finale <- paste(
"== See also ==
* [[Handprinter]]
* [[Developing branches]]
",
"== Related files ==
",
sep = ""
)
text1 <- ""
if(!is.logical(newpage)) text1 <- paste(text1, newpage, collapse = "")
if(!is.logical(newdata)) text1 <- paste(text1, newdata, collapse = "")
if(!is.logical(newformula)) text1 <- paste(text1, newformula, collapse = "")
if(!is.logical(newpage)) text1 <- paste(text1, finale, collapse = "")
text2 <- strsplit(text1, split = "\n")[[1]]
text2 <- gsub("@@", "\\n", text2)
text2 <- gsub("¤", "<", text2)
text2 <- data.frame(Pagetemplate = text2)
oprint(text2, include.rownames = FALSE)
| |