How to call a function from another r file ? Anyone can help me . Having a function named like fun1 which is saved in r file file1.r and i have another r file like file2.r, and i need to call the fun1 (which is in file1) within file2. Thank you -- View this message in context: http://r.789695.n4.nabble.com/function-call-from-another-r-file-tp4650627.html Sent from the R help mailing list archive at Nabble.com.
It is straightforward to load function definitions into memory using the source() function. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. sheenmaria <sheenmaria6 at gmail.com> wrote:>How to call a function from another r file ? >Anyone can help me . > >Having a function named like fun1 which is saved in r file file1.r >and i have another r file like file2.r, and i need to call the fun1 >(which >is in file1) within file2. > >Thank you > > > > >-- >View this message in context: >http://r.789695.n4.nabble.com/function-call-from-another-r-file-tp4650627.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at r-project.org mailing list >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.
If you want to handle a generic case, best thing is to create an R package. It is much easier to manage that using source(), if you have lots of different functionality and data files. Also look at ?system.file. On Sat, Nov 24, 2012 at 7:49 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> It is straightforward to load function definitions into memory using the source() function. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > sheenmaria <sheenmaria6 at gmail.com> wrote: > >>How to call a function from another r file ? >>Anyone can help me . >> >>Having a function named like fun1 which is saved in r file file1.r >>and i have another r file like file2.r, and i need to call the fun1 >>(which >>is in file1) within file2. >> >>Thank you >> >> >> >> >>-- >>View this message in context: >>http://r.789695.n4.nabble.com/function-call-from-another-r-file-tp4650627.html >>Sent from the R help mailing list archive at Nabble.com. >> >>______________________________________________ >>R-help at r-project.org mailing list >>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. > > ______________________________________________ > R-help at r-project.org mailing list > 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.
On Sat, Nov 24, 2012 at 12:26 PM, Suzen, Mehmet <msuzen at gmail.com> wrote:> If you want to handle a generic case, best thing is to create an R > package.And better than best is to use devtools to save you a fiddly edit/build/install cycle. You don't even have to think of it as a package, its just a folder called R with your .R files in, and a DESCRIPTION file (metadata is always a good thing), and your functions get attached in a separate position so they don't clutter ls(), and load_all() will load the just the ones you've edited. Magic. http://rpubs.com/geospacedman/lazydevtools Easy peasy. Barry