#
# Test file with various ways of defining a function		[E.Korsching 2026]
#


# end with comment
a1 <- function(x){ sin(x) }		#comment a1
# end with space + tab
a2 <- function(x){ sin(x) } 	
# end with }
a3 <- function(x){ sin(x) }
# space between ) {
a4 <- function(x) { sin(x) }
# tab between ) {
a5 <- function(x)	{ sin(x) }
# no param
a6 <- function(){ 1+2 }
# space between round bracket
a7 <- function( ){ 1+2 }
# space between round bracket and comment
a8 <- function( ){ 1+2 }	# comment a8
# no curly brackets only if it is a one line function
a9 <- function(x) max(x)*2 - min(x) + ab/ac		# comment a9


# parameter in one line and {
ab1 <- function(x, y, z=c(1,2,3)){
	# comment ab1
	aa <- x*y*z
	aa
}
# parameter in one line and spaces ) ) { and tab comment \n\t further comment
ab2 <- function(x, y, z=c(1,2,3) ) {	# comment 1 ab2
	# comment 2 ab2
	aa <- x*y*z
	aa
}
# parameter in one line, comment and \n curly bracket
ab3 <- function(x, y, z)	# alternate comment
{
	aa <- x*y*z
	aa
}


# parameter on many lines
b1 <- function(x,
	y,
	z=c(1,2,3)){
	# comment b1
	aa <- x*y*z
	aa
}
# parameter on many lines + comment + space )) {
b2 <- function(x,	# comment0
	y,		# comment1
	z=c(1,2,3)) {
	# comment b2
	aa <- x*y*z
	aa
}
# parameter on many lines + comment also after curly bracket
b3 <- function(x,	# comment0
	y,		# comment1
	z=c(1,2,3)){	# comment 1 b2
	# comment 2 b3
	aa <- x*y*z
	aa
}
# parameter on many lines + comment + curly bracket next line
b4 <- function(x,	# comment0
	y,		# comment1
	z=c(1,2,3))
{
	# comment b4
	aa <- x*y*z
	aa
}
# parameter on many lines + comment + )space) + curly bracket next line
b5 <- function(x,	# comment0
	y,		# comment1
	z=c(1,2,3) )
{
	# comment b5
	aa <- x*y*z
	aa
}
# parameter on many lines + comment + round and curly bracket next lines
b6 <- function(x,	# comment0
	y,		# comment1
	z=c(1,2,3)	# comment2
	)
{
	# comment b6
	aa <- x*y*z
	aa
}
# parameter on many lines + x next line + comment + round and curly bracket next lines
b7 <- function(
	x,	# comment0
	y,		# comment1
	z=c(1,2,3)	# comment2
	)
{
	# comment b7
	aa <- x*y*z
	aa
}
# parameter on many lines + x next line + comment + round and curly bracket next lines + no comment after {
b8 <- function(
		x,	# comment0
		y,		# comment1
		z=c(1,2,3)	# comment2
)
{
	aa <- x*y*z
	aa
}
# parameter on many lines + x next line + comment + round and curly bracket next lines + no comment after { + for loop /w {} inside body
b9 <- function(
		x,	# comment0
		y,		# comment1
		z=c(1,2,3)	# comment2
)
{
	aa <- x*y*z
	for(i in 1:10){
		bb <- 1+i
	}
	aa
}


# parameter on many lines + x next line + comment + round and curly bracket next lines + no comment after { + for loop /w {} inside body
#   plus internal functions
c1 <- function(
		x,	# comment0
		y,		# comment1
		z=c(1,2,3)	# comment2
)
{
	f1 <- function(x) { x/2 }	# embedded function one line
	f2 <- function(x,y){	# embedded function multiple lines
		z <- x+y
	}
	z1 <- apply(x, 2, function(x){ x-x })	# embedded anonymous function
	aa <- x*y*z
	for(i in 1:10){
		bb <- 1+i
	}
	aa
}







