0

I want to print every argument passed to function read.table. My idea was to write some decorator that is easy in Python. But for R, I don't know how to do it, what I learned was to use trace(). However, I don't know how to print variables inside trace.

Example:

trace(f)
a <- "123"
f(a)
untrace(f)

trace() will only output f(a), but I want to know the evaluation of a.

  • print function from base r will help you – Hunaidkhan Oct 10 '18 at 04:21
  • Loosely related: if you are talking about overriding the base function `read.table` so that you know when it is being used (with or without your knowledge), then you are talking about over-riding a function in another package and this might be a relevant link: https://stackoverflow.com/a/26647570/3358272. If you want to write your own function that you will use as a wrapper but nothing else uses it unless you tell it to, then just write your own function and use `print` or `message` or even `cat`. – r2evans Oct 10 '18 at 04:51
  • You may want to check out [my answer to a related question](https://stackoverflow.com/a/52689148/8386140). I think you could easily adapt the commands there to suit your needs. – duckmayr Oct 10 '18 at 05:37
  • First you ask for "paths" passed to read.table. There's no path argument given to read.table. If you are asking that the read.table function be redefined to emit the all the parameters passed to read.table then it is a duplicate to duckmayer`s answered question. – IRTFM Oct 10 '18 at 06:58
  • Thanks for your guys reply. duckmayer`s answer is related to what I want, however, for that post, what if I have myfun(1,d) where d is a variable, how can I print the evaluation of the argument d? (e.g. d<-3, myfun(1,d) only prints d) – Aaron Shixiang Zhou Oct 10 '18 at 13:41

1 Answers1

0

thanks for your guys' help, I find the answer.

Simply use the following code:

trace(f, tracer = quote(print(lapply(as.list(match.call()),eval))))
d<-1
f(d)
untrace(f)