Skip to content

Commit

Permalink
Add a template project #208
Browse files Browse the repository at this point in the history
  • Loading branch information
gaow committed Nov 27, 2019
1 parent 4238763 commit 6ab7fe4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dscrutils/inst/template/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.dsc linguist-language=YAML
1 change: 1 addition & 0 deletions dscrutils/inst/template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.sos
3 changes: 3 additions & 0 deletions dscrutils/inst/template/modules/analyze.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mean: utils.R + R(y <- mean(x))
x: $data
$est_mean: y
4 changes: 4 additions & 0 deletions dscrutils/inst/template/modules/score.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sq_err: utils.R + R(e <- (x - y)^2)
x: $est_mean
y: $true_mean
$error: e
5 changes: 5 additions & 0 deletions dscrutils/inst/template/modules/simulate.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
normal: utils.R + R(x <- rnorm(n,mean = mu,sd = 1))
mu: 0
n: 100
$data: x
$true_mean: mu
1 change: 1 addition & 0 deletions dscrutils/inst/template/src/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# codes and functions to use as DSC modules
16 changes: 16 additions & 0 deletions dscrutils/inst/template/template.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env dsc

#
# example usage: ./template.dsc --replicate 10
#

%include modules/*.dsc

DSC:
define:
simulate: normal
analyze: mean
score: sq_err
run: simulate * analyze * score
output: template_out
exec_path: src
13 changes: 7 additions & 6 deletions src/dsc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ def load_dsc(fn):
raise FormatError(f'Invalid statement ``{line[0]}``. Perhaps you meant to use ``%include``?')
if len(line) != 2:
raise FormatError(f'Invalid %include statement ``{" ".join(line)}``. Should be ``%include filename.dsc``')
if not os.path.isfile(line[1]) and os.path.isfile(line[1] + '.dsc'):
new_content.extend(DSC_Script.load_dsc(line[1] + '.dsc'))
elif os.path.isfile(line[1]):
new_content.extend(DSC_Script.load_dsc(line[1]))
else:
raise FormatError(f'Cannot find file ``{line[1]}`` to include.')
for f in glob.glob(line[1]):
if not os.path.isfile(f) and os.path.isfile(f + '.dsc'):
new_content.extend(DSC_Script.load_dsc(f + '.dsc'))
elif os.path.isfile(f):
new_content.extend(DSC_Script.load_dsc(f))
else:
raise FormatError(f'Cannot find file ``{f}`` to include.')
return new_content + [x for x in content if not x.startswith('%') and not x.startswith('#!')]

def update(self, text, exe):
Expand Down

0 comments on commit 6ab7fe4

Please sign in to comment.