Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/demo.r
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions R/getFunctions.R
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 37 additions & 0 deletions R/micro.R
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 42 additions & 0 deletions R/micro2.R
Original file line number Diff line number Diff line change
@@ -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)



66 changes: 51 additions & 15 deletions R/prov.capture.R
Original file line number Diff line number Diff line change
@@ -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")

Empty file added R/test
Empty file.
41 changes: 41 additions & 0 deletions R/test.R
Original file line number Diff line number Diff line change
@@ -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)