[R] Including an external set of coded

CALUM POLWART po|c1410 @end|ng |rom gm@||@com
Tue Feb 20 17:43:58 CET 2024


Are you asking to source lines 5-10 of a file for instance?

Never seen that done in R. Feels a dodgy thing to do as changing line will
screw things up.  On the other hand - I'd often have functions in a file
called perhaps "functions.R" and source("functions.R")

Then I can call an individual function something like

tranform_mydata(mydata)



With the functions.R containing

transform_mydata <- function (mydata) {

mydata<-transform(mydata,
a<-b+c
d<-e+f

return(mydata)
}

On Tue, 20 Feb 2024, 15:46 Bert Gunter, <bgunter.4567 using gmail.com> wrote:

> I believe you will have to expain what you want more fully, as what you
> requested appears to be exactly what source() does, to me anyway. Please
> reread its help file more carefully perhaps?
>
> -- Bert
>
> On Tue, Feb 20, 2024 at 7:36 AM Steven Yen <styen using ntu.edu.tw> wrote:
>
> > How can I call and include an external set of R codes, not necessarily a
> > complete procedure (which can be include with a “source” command).
> Example:
> >
> > #I like to include and run the following lines residing in a file outside
> > the main program:
> >
> > mydata<-transform(mydata,
> > a<-b+c
> > d<-e+f
> > }
> >
> >
> > Steven from iPhone
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list