[R] Execution of a function

arun smartpink111 at yahoo.com
Tue Aug 7 23:21:51 CEST 2012


HI,
Suppose, I have a function like this:

fun1<-function(x){
 ifelse(x[1]<0,
 sum(x[min(which(x<0)):(which.max(x>0)-1)]),
sum(x[min(which(x<0)):max(which(x<0))])
)
 }

#And I save it as "aj.fun" (-- filename)
#Then,
>source("aj.fun")
> fun1
function(x){
 ifelse(x[1]<0,
 sum(x[min(which(x<0)):(which.max(x>0)-1)]),
sum(x[min(which(x<0)):max(which(x<0))])
)
 }

a1<-c(-5,-2,4,2,-4,-6,3)

> fun1(a1)
#[1] -7

Hope this helps.
A.K.


----- Original Message -----
From: hafida <hafida-06 at hotmail.fr>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, August 7, 2012 12:26 PM
Subject: [R] Execution of a function

Hi

>i have  aproblem withe execution of my function

>first, i wrote my function in the script of R 
>nom_fonction <- function(arg1[=expr1], arg2[=expr2], ...){ 
bloc d'instructions
}

> when i want to have the result i mean the laste instruction in the bloc of
> instruction ,  i try to
>wrote the name of function

>source(aj.fun)
Error in readLines(file, warn = FALSE) : 'con' is not a connection

>return(aj.fun)
Error: no function to return from, jumping to top level

thanks for helping
hafida, univ of algeria 






--
View this message in context: http://r.789695.n4.nabble.com/Execution-of-a-function-tp4639424.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.




More information about the R-help mailing list