[R] Including an external set of coded

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


What happens if you add a line to the code in lines 1-5.  So line 5 is now
line 6 etc?

Your "procedure" needs a name

So either it's a function, OR, we each procedure is a file to source?

On Tue, 20 Feb 2024, 16:55 Steven Yen, <styen using ntu.edu.tw> wrote:

> I see——still put those lines in a procedure and call the procedure by
> “source”. I source procedures all the time.
>
> I just wondered whether there is a way to “source” these lines without
> putting them in a procedure. Because I have too many of such lines which I
> use in several main programs annd only reason I want to do this is to keep
> my main programs compact.
>
> Steven from iPhone
>
> On Feb 21, 2024, at 12:44 AM, CALUM POLWART <polc1410 using gmail.com> wrote:
>
> 
> 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