È possibile chiamare source("abc.R")
seguito da source("xyz.R")
(assumendo che entrambi questi file sono nella directory di lavoro corrente
Se abc.R è:.
fooABC <- function(x) {
k <- x+1
return(k)
}
e xyz.R è:
fooXYZ <- function(x) {
k <- fooABC(x)+1
return(k)
}
allora questo lavoro:
> source("abc.R")
> source("xyz.R")
> fooXYZ(3)
[1] 5
>
Anche se ci sono delle dipendenze cicliche, questo funzionerà.
E.g. Se abc.R è questo:
fooABC <- function(x) {
k <- barXYZ(x)+1
return(k)
}
barABC <- function(x){
k <- x+30
return(k)
}
e xyz.R è questa:
fooXYZ <- function(x) {
k <- fooABC(x)+1
return(k)
}
barXYZ <- function(x){
k <- barABC(x)+20
return(k)
}
poi,
> source("abc.R")
> source("xyz.R")
> fooXYZ(3)
[1] 55
>
fonte
2012-11-25 10:57:21
Utilizzando tali funzioni. Più seriamente guarda in 'source' – Dason