peijianshi 发表于 2014-11-2 19:10 
比如编写一个函数,名为"myfun",而在这个R文件下边还有一些命令(比如有五行),当调用时source("myfun" ...
这应该属于程序组织的问题。
要分清函数和主程序的关系,break只是跳出循环,q()是结束整个程序的运行。基于楼主的问题,猜测应这样组织程序:
#首先定义myfun函数
myfun<-function(){
if(meetSomeCondition) {
doSomething
}else{
#"不运行下面的程序"
doOtherThing
}
}
#其次在主程序(或主函数)中按顺序执行即可
myfun()
doLastFiveLinesCodeHere_line1
doLastFiveLinesCodeHere_line2
doLastFiveLinesCodeHere_line3
doLastFiveLinesCodeHere_line4
doLastFiveLinesCodeHere_line5