how to load my own function automatically as R-package? [closed] - r

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I built my own function and each time I need to run this function, I need to do that manulally. Is there any way that I can load it automatically as any R-package? Or can I build an R-package used only by me?

Would recommend Nate Days solution, but you could also use Rs save() and load()functions to do this. It works on all R-objects and stores them in a binay .rda-file. You can store multiple objects as well.
Try:
add <- function(x, y){return(x+y)}
save(add, file = 'add_function.rda')
Whenever you need your function, do:
load('add_function.rda')
And add() would be available in the parent environment.

There is a package called pkgmaker on CRAN that has a ton of tools and utilities for you to create your own packages. As an alternate option you might consider creating a functions.R script for you to store all of your personally created and often used functions. You can add the line source('functions.R', local=TRUE) to your programs, scripts or apps and your functions will be accessible to you. Thats how I handle the issue anyway. Cheers

Related

Should I make my R developments a package? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am developing a set of R scripts to post-process experimental data.
Currently, these are just scripts that I load individually by manually sourcing them.
I wonder if it would be better to put all those scripts in an R package, but as I constantly add/modify my library functions, I don't really know if this is the recommended way of doing it.
So my question is: should I go on working on "independent" script files or package them?
It is always good to bundle your scripts into a package. which will help you in lot many ways.
All your project fundamentals will be packed together
code portability will be lot easier
you can have test cases for your function using testthat package
You can have proper documentation for your code using roxygen2 package, which will help the readers or other users of the code to understand mode about the code.
you don't have to load your data and functions manually, you just have to load your package by saying library(package_name)
for more details about "R package": http://r-pkgs.had.co.nz/

How R Language works [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was kind of wondering,how R language works internally when we type some command..
Say License()
As per my understanding,R language is made of packages,When we execute some command,it invokes the Right package,i was not able to find some documentation supporting this..
Research done from side:
1.closest i could get is below link
https://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf
2.I searched using "How R Language works internally",but i could not get any relevant results..
Below is how SQLServer executes a query from starting to end ,i am looking to see similar kind of documentation/any pointers for R
please let me know if you have any pointers
The notion that the R language is "made of packages" is inaccurate. It is made of commands, operators and functions, like other programming languages. Those commands are grouped into namespaces which comprise commands that belong to the same topic. A package provides a set of specific commands (and sometimes other objects, like sample data) grouped into a namespace. By loading a library (there are subtle semantic differences between a library and a package) the namespace of the package becomes available in the global environment, thereby making these commands directly accessible.
On the suggestion of #CapelliC here is a fully typed answer.
The internals of R are included in the document: https://cran.r-project.org/doc/manuals/r-release/R-ints.html
It is not an easy read, but covers all of the detail. My advice would be search the document if you have a specific query...

Proper Coding Techniques in R [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am writing an R code that has many different functions that eventually I will want to use all together on different data sets.
As I keep building functions it seems to be getting harder to keep track of everything in my script.
My question is, is it proper R coding to break functions into separate R Scripts or should it all be in one massive script?
Thank you for your help. This is my first time trying to code something this large!
-B
Yes, you can store your functions in multiple R scripts.
If you need to call them, you can use source().
For eg:
Say you have func1 , func2 saved in myfunc.R.
To call them,
source('myfunc.R')
#other codes
func1()
func2()
As to whether this approach is recommended, depends on your project requirements.
Alternatively, you can consider packaging them as recommended by Richard.

Can I write go library to be used from another languages? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm writing relatively small, but not simple networking library which is going to be used at least from C,java,python,ruby and C#. Is there a way to make go bindings to the other languages the way in can be done form C? If not is there other way?
Right now, you can't write libraries in Go that can be used in other languages. Go has a runtime environment that does a lot of things (like sheduling go-routines, collecting garbage) for you. This runtime environment is written under the assumption that it controls the whole program. This assumption does not hold if Go code would be used from inside another language, as the Go library cannot influence the binary that uses it.
I imagine that a JSON service would do what you describe.
Have a look at the json test for a simple example
It wouldnt matter what languages you used to set and get data from your app

how to view help document in R windows just like the way in linux? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I would like to know how to view R help document in windows, just like the way it is when using Linux. That is to say, the help document is shown in the same terminal of the running R program; within it I just type ?help command.
options(help_type="text") will pop up a text window within R, rather than displaying help in the browser. You can't actually display help inside the R console, though. (Not even when using the console versions of R, strangely enough.)
One option is to use one of the many R GUI environments available on Windows--these generally provide docs in the same "window" (thought not in the R terminal itself). If that's close enough for you, try RStudio or RKWard.

Resources