# NOT RUN {
library(spec) # read and write data specifications
library(latexpdf) # make dummy logo for pdf
library(encode) # encode factor levels for spec file
dir <- tempdir() # a place to experiment
dir <- gsub('\\\\','/',dir) # clean up windows path
outdir <- file.path(dir,'out') # where to put the define archive
csv <- file.path(dir,'theoph.csv') # path to data
script <- file.path(dir,'theoph.R') # path to script making data
spec <- file.path(dir,'theoph.spec') # path to data specification
# make dummy logo
# }
# NOT RUN {
as.pdf('{\\huge \\em Pharma, Inc.}',wide = 50, long = 8,stem = 'logo', dir = dir)
# }
# NOT RUN {
# browseURL(system.file(package = 'define', 'logo.pdf')) # cached
logo <- system.file(package = 'define', 'logo.pdf') # path to dummy logo
# make data more interesting
Theoph$renal <- 0
# create script
code <- "write.csv(x = Theoph,file = csv,row.names = FALSE,quote = FALSE)"
writeLines(code,script)
# 'run' the script
eval(parse(text = code))
# make data specification
s <- specification(Theoph)
renalcat <- c(
'GFR >= 90 mL/min/1.73m^2',
'60 <= GFR < 90 mL/min/1.73m^2',
'45 <= GFR < 60 mL/min/1.73m^2',
'30 <= GFR < 45 mL/min/1.73m^2',
'GFR < 30 mL/min/1.73m^2'
)
codes <- encode(0:4, renalcat)
codes
s$guide[s$column == 'renal'] <- codes
write.spec(s,spec)
file.exists(csv)
file.exists(spec)
# define(c(theoph = csv),stem = 'minimal',dir = outdir, clean=FALSE)
# browseURL(file.path(outdir,'minimal.pdf'))
# browseURL(system.file(package = 'define', 'minimal.pdf')) # cached
# }
# NOT RUN {
define(
x = c(
theodat = csv,
theoprg = script
),
subdir = c(
'm5/datasets/analysis/datasets',
'm5/datasets/analysis/programs'
),
description = c(
'Theophylline PK Dataset',
'Theophylline PK Script'
),
title = 'Pharmacokinetics of Theophylline',
short = 'Theophylline PK',
protocol = 'Protocol tpk-001',
sponsor = 'Pharma, Inc.',
program = 'Theophylline',
author = 'define package for R',
logo = logo,
logoscale = 2,
clear = FALSE,
dir = outdir
)
# browseURL(file.path(outdir,'define.pdf'))
# }
# NOT RUN {
# browseURL(system.file(package = 'define','define.pdf')) # cached
# browseURL(system.file(package = 'define','poster.pdf')) # earlier work
# Alternatively, supply aesthetics by position:
# }
# NOT RUN {
define(
x = c(
theodat = csv,
theoprg = script
),
subdir = c(
'm5/datasets/analysis/datasets',
'm5/datasets/analysis/programs'
),
description = c(
'Theophylline PK Dataset',
'Theophylline PK Script'
),
title = 'Pharmacokinetics of Theophylline',
lhead1 = 'Theophylline PK',
lhead2 = 'Protocol tpk-001',
rhead1 = 'Pharma, Inc.',
rhead2 = 'Theophylline',
lfoot = 'define package for R',
rfoot = '\\mydate \\today',
logo = logo,
logoscale = 2,
clear = FALSE,
dir = outdir
)
# }
# NOT RUN {
# Tags for elements of x can be given explicitly rather than as names:
# }
# NOT RUN {
define(
x = c(csv, script),
tag = c('theodat','theoprg'),
subdir = c(
'm5/datasets/analysis/datasets',
'm5/datasets/analysis/programs'
),
description = c(
'Theophylline PK Dataset',
'Theophylline PK Script'
),
title = 'Pharmacokinetics of Theophylline',
lhead1 = 'Theophylline PK',
lhead2 = 'Protocol tpk-001',
rhead1 = 'Pharma, Inc.',
rhead2 = 'Theophylline',
lfoot = 'define package for R',
rfoot = '\\mydate \\today',
logo = logo,
logoscale = 2,
clear = FALSE,
dir = outdir
)
# }
# NOT RUN {
# If the title is short, no need to supply a short version.
# Most arguments have suitable defaults. But be sure to
# supply tags, or names for elements of x.
# }
# NOT RUN {
define(
x = c(
theodat = csv,
theoprg = script
),
description = c(
'Theophylline PK Dataset',
'Theophylline PK Script'
),
title = 'Theophylline PK',
dir = outdir
)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab