Waichler, Scott R
2006-Jun-27 18:55 UTC
[R] Possible to get a definition of a function from a package to use without invoking the package?
Hi, I often use the mod() and instring() functions that are available in the clim.pact package. This package has a lot of dependencies, including installation of netCDF, and I haven't yet been able to get library(clim.pact) to work on a Mac OS 10.4.6. A previous request for help with the Mac problem yielded no results, so now I wonder if I could just extract the definitions for the couple of functions that I need and save them in my own file of R functions. I'm pretty sure that mod() and instring() are very basic and don't have any exotic dependencies. I did find an alternative mod() in the new matlab package, and that's fine. Now I just need another way to get the instring() functionality. Thanks, Scott Waichler Pacific Northwest National Laboratory scott.waichler _at_ pnl.gov
Gabor Grothendieck
2006-Jun-27 19:12 UTC
[R] Possible to get a definition of a function from a package to use without invoking the package?
You can use %% instead of mod, e.g. 12 %% 5 see ?"%%" You can use unlist(gregexpr(pat, string, fixed = TRUE)) instead of instring(pat, string). If you just want the first occurrence use regexpr instead of gregexpr. On 6/27/06, Waichler, Scott R <Scott.Waichler at pnl.gov> wrote:> > Hi, > > I often use the mod() and instring() functions that are available in the > clim.pact package. This package has a lot of dependencies, including > installation of netCDF, and I haven't yet been able to get > library(clim.pact) to work on a Mac OS 10.4.6. A previous request for > help with the Mac problem yielded no results, so now I wonder if I could > just extract the definitions for the couple of functions that I need and > save them in my own file of R functions. I'm pretty sure that mod() and > instring() are very basic and don't have any exotic dependencies. I did > find an alternative mod() in the new matlab package, and that's fine. > Now I just need another way to get the instring() functionality. > > Thanks, > Scott Waichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnl.gov > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Roger D. Peng
2006-Jun-27 19:12 UTC
[R] Possible to get a definition of a function from a package to use without invoking the package?
You should be able to download the source package from CRAN and copy the code for the 'instring()' function into your own source file. -roger Waichler, Scott R wrote:> Hi, > > I often use the mod() and instring() functions that are available in the > clim.pact package. This package has a lot of dependencies, including > installation of netCDF, and I haven't yet been able to get > library(clim.pact) to work on a Mac OS 10.4.6. A previous request for > help with the Mac problem yielded no results, so now I wonder if I could > just extract the definitions for the couple of functions that I need and > save them in my own file of R functions. I'm pretty sure that mod() and > instring() are very basic and don't have any exotic dependencies. I did > find an alternative mod() in the new matlab package, and that's fine. > Now I just need another way to get the instring() functionality. > > Thanks, > Scott Waichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnl.gov > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger D. Peng | http://www.biostat.jhsph.edu/~rpeng/
Duncan Murdoch
2006-Jun-27 19:22 UTC
[R] Possible to get a definition of a function from a package to use without invoking the package?
On 6/27/2006 2:55 PM, Waichler, Scott R wrote:> Hi, > > I often use the mod() and instring() functions that are available in the > clim.pact package. This package has a lot of dependencies, including > installation of netCDF, and I haven't yet been able to get > library(clim.pact) to work on a Mac OS 10.4.6. A previous request for > help with the Mac problem yielded no results, so now I wonder if I could > just extract the definitions for the couple of functions that I need and > save them in my own file of R functions.I'm not sure what you mean by this question. Technically you can do that. Legally you can do it because clim.pact is GPL'd. It's a slightly rude thing to do if you end up redistributing the functions, so I'd check with the author first. It may cause you weird problems in the future if you decide to use both your functions and clim.pact at the same time, especially if one of them has mutated in the meantime. I'd suggest the best approach is to work with the clim.pact author to get that package working on your platform. By the way, mod() is available as a basic R operator, namely %%. It provides different results in some cases, e.g. > -5 %% 2 [1] 1 > mod(-5, 2) [1] -1 so be careful about your definitions. I don't know a simple substitute for instring(). Duncan Murdoch I'm pretty sure that mod() and> instring() are very basic and don't have any exotic dependencies. I did > find an alternative mod() in the new matlab package, and that's fine. > Now I just need another way to get the instring() functionality. > > Thanks, > Scott Waichler > Pacific Northwest National Laboratory > scott.waichler _at_ pnl.gov > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Seemingly Similar Threads
- Problems with Raster and clim.pact packages with large netcdf files (2.7G) in x64 bit R
- doubt in climate variability analysis in R!
- levelplot and unequal cell sizes
- Problem with R-2.1.0: install.packages() doesn't work
- Timeliness of precompiled binaries--R-2.2.1 still not available as RPM