Reputation: 10570
I am planing to do all my R scripts in the same package in order to move it easily between my friends.
What I have done is created an R packages using R studio and the following files have been automatically generated:
projectName.Rproj
DESCRIPTION
man
NAMESPACE
R
Read-and-delete-me
I created a new R script and I save it in R
folder. Now I want to add a new R script that uses functions that have been defined in the first script.
I created this new script and I tried to use on of the functions that are located in the other script. I got error that the function is not defined.
I used the source
command in the beginning of the new script like this:
source('something.R')
I got error message that something.R
doesn't exist.
What is the solution please to include functions that exist in a different scripts ** but in the same packages**?
Thanks a lot
Upvotes: 0
Views: 91
Reputation: 368181
You appear to misunderstand how package works: by having a file with a function in the R/
directory, it is already visible to other code in the package.
If you want to make it available to other packages, you can control this via the NAMESPACE
file. All this is well-documented in Writing R Extensions which comes with your copy of R, and a number of additional books and tutorials you could peruse.
Upvotes: 3