?source
states:
Description:
‘source’ causes R to accept its input from the named file or URL
or connection. Input is read and ‘parse’d from that file until
the end of the file is reached, then the parsed expressions are
evaluated sequentially in the chosen environment.
Therefore,
source
is the function you are looking for,
- I refute your claim -
source
works for me as per the documentation
If you are not seeing the documented behaviour then there must be a different problem that you are not telling us.
How are you deducing that source
is not executing your f
?
I can think of one scenario that you may not be aware of, which is documented in ?source
, namely:
Details:
Note that running code via ‘source’ differs in a few respects from
entering it at the R command line. Since expressions are not
executed at the top level, auto-printing is not done. So you will
need to include explicit ‘print’ calls for things you want to be
printed (and remember that this includes plotting by ‘lattice’,
FAQ Q7.22).
Not seeing the output from objects called by name or grid graphics-based plots not showing are symptoms of auto-printing not being active as the evaluation is not occurring at the top-level. You need to explicitly print()
objects, including grid-based graphics like Lattice and ggplot2 figures.
Also note the print.eval
argument, which will default to
> getOption("verbose")
[1] FALSE
which may also be of use to you.