.setUp <- function(){
	.setUpDf <- within( list(),{
			fList <- list(
				function(...){ "Hello world!" }	# put the dots so that other functoins can have arguments
				,function(a){ a }
.tearDown <- function () {

test.sfParInternal <- function(){
	checkEquals("Hello world!", .sfParInternal( 1, fList, a="ah"))
	checkEquals("ah", .sfParInternal( 2, fList, a="ah"))
	checkException( .sfParInternal( 2, fList))	#error because argument is missing
	checkException( .sfParInternal( 2, fList, sfParArgsList="ah"))	#error message because is not a list

test.sfParSequential <- function(){
	.exp <- list("Hello world!","aha")
	checkEquals(.exp, sfPar( fList, sfParParallel=FALSE, a="aha" ))
	checkEquals(.exp, sfPar( fList, sfParParallel=FALSE, sfParArgsList=list(a="aha") ))	
	checkException( sfPar( fList, sfParParallel=FALSE, "aha" ))	#error
	checkException( sfPar( fList, sfParParallel=FALSE, sfParArgsList=list(a="aha"), a="ahb" ))	
	checkEquals(.exp,sfPar( fList, sfParArgsList=list(a="aha") ))	
	checkEquals(.exp,sfPar( fList, a="aha" ))
	aPre = "aha"
	checkEquals(.exp,sfPar( fList, a=aPre ))	#should work, ... are evaluated before distribution
	#checkEquals(.exp,sfPar( fList,"aPre") ))	#does not work aPre is not known in sfPar, because sfPar is not defined in current scope 
	if( sfParallel() ){
	  checkException(sfPar( fList, sfParArgsList=list("aPre")) ))	#should give an error because not yet exported
	  checkEquals(.exp, sfPar( fList, sfParArgsList=list("aPre")) ))	#should work now

Try the twSnowfall package in your browser

Any scripts or data that you put into this service are public.

twSnowfall documentation built on May 2, 2019, 4:47 p.m.