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/getFunctions.R b/R/getFunctions.R new file mode 100644 index 0000000..0a3fa0f --- /dev/null +++ b/R/getFunctions.R @@ -0,0 +1,11 @@ +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 +# 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 new file mode 100644 index 0000000..45a1b9f --- /dev/null +++ b/R/micro.R @@ -0,0 +1,37 @@ + +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) 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/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") + 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) + + +