From 6a4d4f1fe5aeee24a6e59854ee2ac5ba78191884 Mon Sep 17 00:00:00 2001 From: Date: Thu, 22 Mar 2018 10:18:38 -0400 Subject: [PATCH 1/3] Added tests --- R/demo.r | 12 +++++++++ R/micro.R | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ R/prov.capture.R | 66 ++++++++++++++++++++++++++++++++++++----------- 3 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 R/demo.r create mode 100644 R/micro.R diff --git a/R/demo.r b/R/demo.r new file mode 100644 index 0000000..2641068 --- /dev/null +++ b/R/demo.r @@ -0,0 +1,12 @@ +myNestedFunc <- function(x){ + return (2 * x) +} + +myFunc <- function(x){ + y <- myNestedFunc(x + 5) + return(y) +} + +myFunc(3) +myFunc(4) +myFunc(5.5) \ No newline at end of file diff --git a/R/micro.R b/R/micro.R new file mode 100644 index 0000000..d5452d1 --- /dev/null +++ b/R/micro.R @@ -0,0 +1,67 @@ + +x <- 1 +capture.output(x) +y <-3 +capture.output(y) +capture.output(10+0) +capture.output(10)#doesn't work +10 #monitor interpreter processing, capture.output(wrap an entire line) +x #1 +x <-x+y +capture.output(x+y)#expression evaluation +x +y^3 +capture.output(y^3) + +#trace(write.csv, tracer = quote(cat(sprintf("Tracing file argument = %s\n", file)))) +trace(write.table, tracer = quote(cat(sprintf("Tracing csv(file = %s)\n", file)))) +write.csv(x,"~/test.test") #traceable +untrace(write.table) + +trace(pdf, tracer = quote(cat(sprintf("Tracing pdf(file = %s)\n", file)))) +pdf("~/test.pdf")#see if can grab all arguments in an ordered list +untrace(pdf) + +trace(plot, tracer = quote(cat(sprintf("Tracing plot(x = %s)\n", x)))) +plot(x)# x +untrace(plot) + +#trace(.External, tracer = quote(cat(sprintf("Finished graphics device monitoring: (.NAME = %s)\n", .NAME)))) +trace(.External, tracer = quote(sprintf("Traced"))) +#trace(dev.cur, exit = quote(cat(sprintf("Finished graphics device monitoring"))), print=FALSE) + +dev.cur() +dev.off()# + +#untrace(dev.cur) +untrace(.External) + +x <- 1 +y <-3 +10 #monitor interpreter processing, capture.output(wrap an entire line) +x #1 +x <-x+y +x +capture.output(x) +capture.output(y) + +y^3 +capture.output(y^3) + +trace(write.table, tracer = quote(cat(sprintf("Tracing csv(file = %s)\n", file)))) +trace(pdf, tracer = quote(cat(sprintf("Tracing pdf(file = %s)\n", file)))) +trace(plot, tracer = quote(cat(sprintf("Tracing pdf(x = %s)\n", x)))) +trace(.External, exit = quote(cat(sprintf("Finished graphics device monitoring\n"))), print=FALSE) + +write.csv(x,"~/test.test") #traceable +pdf("~/test.pdf")#see if can grab all arguments in an ordered list +plot(x)# x +dev.off()# + +untrace(write.table) +untrace(pdf) +untrace(plot) +untrace(.External) + + + diff --git a/R/prov.capture.R b/R/prov.capture.R index 97f994a..dc3e150 100644 --- a/R/prov.capture.R +++ b/R/prov.capture.R @@ -1,15 +1,51 @@ -#' prov.capture --- Capture R language provencance. -#' OUTPUT = Provenance from code stored in memory. -#' -#' Captures and records provenance from a script provided by the user. -#' -#' @param x A script who's provenance should be recorded. -#' @return Stores provenance in memory in PROV-JSON format. -#' @importFrom base trace -#' @export prov.capture -#' @author ELizabeth Hu and Matthew K. Lau - -prov.capture <- function(x = "script"){ - #### Insert funcntion tracing activities here - -} +#' prov.capture --- Capture R language provencance. +#' OUTPUT = Provenance from code stored in memory. +#' +#' Captures and records provenance from a script provided by the user. +#' +#' @param script A script who's provenance should be recorded. +#' @return Stores provenance in memory in PROV-JSON format. +#' @importFrom base trace +#' @export prov.capture +#' @author ELizabeth Hu and Matthew K. Lau + +prov.capture <- function(script){ + #### Insert function tracing activities here + + fnames = list("myFunc") + print(fnames) + ### User defined functions + + ddg.annotate <- function(fnames){ + if (is.null(fnames)) { + return() + } + + getCall <- function(){ + i <- -1 + while (as.character(sys.call(i)[1]) != ".doTrace") + i <- i - 1 + call <- sys.call(i-1) + callName <- as.character(call[[1]]) + print(cat(sprintf("Function called: %s\n", callName))) + } + #trace the call of myNestedFunc within myFunc + for(f in fnames){ + f = quote(get(f)) + trace(f, getCall, exit = quote(cat(sprintf("Return = %.5g\n", returnValue())))) + } + source("demo.r", print.eval = TRUE) + print("Ending script run") + for(f in fnames){ + untrace(f) + } + + + } + #set to working directory with the script + ddg.annotate(fnames) + +} + +prov.capture("demo.r") + From 4af8d988eab35de3868e985ba2cd4dadb7f4ee67 Mon Sep 17 00:00:00 2001 From: Date: Wed, 11 Apr 2018 15:58:45 -0400 Subject: [PATCH 2/3] scripts --- R/getFunctions.R | 12 ++++++++++++ R/micro.R | 30 ------------------------------ R/micro2.R | 42 ++++++++++++++++++++++++++++++++++++++++++ R/test | 0 R/test.R | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 30 deletions(-) create mode 100644 R/getFunctions.R create mode 100644 R/micro2.R create mode 100644 R/test create mode 100644 R/test.R diff --git a/R/getFunctions.R b/R/getFunctions.R new file mode 100644 index 0000000..2c72ef4 --- /dev/null +++ b/R/getFunctions.R @@ -0,0 +1,12 @@ +library("NCmisc") +listresult <- list.functions.in.file("test.R") +listresult <- unlist(unname(listresult)) + +for(f in listresult){ + print(f) + print(formals(f)) +} + +#grab each of the functions, separated by package +# run args(function) to retrieve the arguments of the function +# trace arguments of the functions (for ex., for filenames) \ No newline at end of file diff --git a/R/micro.R b/R/micro.R index d5452d1..45a1b9f 100644 --- a/R/micro.R +++ b/R/micro.R @@ -35,33 +35,3 @@ dev.off()# #untrace(dev.cur) untrace(.External) - -x <- 1 -y <-3 -10 #monitor interpreter processing, capture.output(wrap an entire line) -x #1 -x <-x+y -x -capture.output(x) -capture.output(y) - -y^3 -capture.output(y^3) - -trace(write.table, tracer = quote(cat(sprintf("Tracing csv(file = %s)\n", file)))) -trace(pdf, tracer = quote(cat(sprintf("Tracing pdf(file = %s)\n", file)))) -trace(plot, tracer = quote(cat(sprintf("Tracing pdf(x = %s)\n", x)))) -trace(.External, exit = quote(cat(sprintf("Finished graphics device monitoring\n"))), print=FALSE) - -write.csv(x,"~/test.test") #traceable -pdf("~/test.pdf")#see if can grab all arguments in an ordered list -plot(x)# x -dev.off()# - -untrace(write.table) -untrace(pdf) -untrace(plot) -untrace(.External) - - - diff --git a/R/micro2.R b/R/micro2.R new file mode 100644 index 0000000..1c51189 --- /dev/null +++ b/R/micro2.R @@ -0,0 +1,42 @@ +x <- 1 +y <-3 +10 #monitor interpreter processing, capture.output(wrap an entire line) +x #1 +x <-x+y +x +capture.output(x) +capture.output(y) + +y^3 +capture.output(y^3) + +trace(write.table, tracer = quote(cat(sprintf("Tracing csv(file = %s)\n", file)))) +trace(pdf, tracer = quote(cat(sprintf("Tracing pdf(file = %s)\n", file)))) +trace(plot, tracer = quote(cat(sprintf("Tracing pdf(x = %s)\n", x)))) +trace(.External, exit = quote(cat(sprintf("Finished graphics device monitoring\n"))), print=FALSE) + +write.csv(x,"~/test.test") #traceable +pdf("~/test.pdf")#see if can grab all arguments in an ordered list +plot(x)# x +dev.off()# + +untrace(write.table) +untrace(pdf) +untrace(plot) +untrace(.External) + +myNestedFunc <- function(x){ + return (2 * x) +} + +myFunc <- function(x){ + y <- myNestedFunc(x + 5) + return(y) +} + +myFunc(3) +myFunc(4) +myFunc(5.5) + + + diff --git a/R/test b/R/test new file mode 100644 index 0000000..e69de29 diff --git a/R/test.R b/R/test.R new file mode 100644 index 0000000..e5330e5 --- /dev/null +++ b/R/test.R @@ -0,0 +1,41 @@ + +x <- 1 +y <-3 +10 #monitor interpreter processing, capture.output(wrap an entire line) +x #1 +x <-x+y +x +y^3 + +write.csv(x,"~/test.test") #traceable + +pdf("~/test.pdf")#see if can grab all arguments in an ordered list + + +plot(x)# x + +dev.cur() +dev.off()# + + +write.csv(x,"~/test.test") #traceable +pdf("~/test.pdf")#see if can grab all arguments in an ordered list +plot(x)# x +dev.off()# + + +myNestedFunc <- function(x){ + return (2 * x) +} + +myFunc <- function(x){ + y <- myNestedFunc(x + 5) + return(y) +} + +myFunc(3) +myFunc(4) +myFunc(5.5) + + + From 0e6a6ebae7ab80bdd3c0674ce82bbb483d6cab5d Mon Sep 17 00:00:00 2001 From: Elizabeth Hu Date: Wed, 11 Apr 2018 16:02:07 -0400 Subject: [PATCH 3/3] scripts --- R/getFunctions.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/getFunctions.R b/R/getFunctions.R index 2c72ef4..0a3fa0f 100644 --- a/R/getFunctions.R +++ b/R/getFunctions.R @@ -8,5 +8,4 @@ for(f in listresult){ } #grab each of the functions, separated by package -# run args(function) to retrieve the arguments of the function # trace arguments of the functions (for ex., for filenames) \ No newline at end of file