I have created a function which works normally when I take it out from the function. However, when I put that in the function and the output is always wrong:
ele_remover <- function(original, remove){
output <- original[-remove]
output
}
ICD4 <- function(num.plots = 240, num.crops = 6, remove.crop.combo){
combination.a <- apply(combn(1:num.crops,2),2,paste0,collapse="")
combination.b <- apply(combn(num.crops:1,2),2,paste0,collapse="")
new.combination <- c(combination.a,combination.b)
combination <- ele_remover(new.combination, remove.crop.combo)
comb.x <- sort(as.numeric(combination))
comb.each <- ceiling(num.plots/length(comb.x))
crop.combinations <- rep(comb.x, each=comb.each)
output <- comb.x
}
ICD4_output <- ICD4(240, 6, c(12,13))
Before the elements is removed from the vector "new.combination", it should be like (11, 12, 13 .... 64, 65); after the function working removed the elements, some of the elements should be removed from the new.combination. So that the final output should contain the left elements in the vector.
I have tried all this outside function, it worked finely! But when I put it back in the function, the removing function never worked normally. Hope to get your support!
CodePudding user response:
Just a quick note since your ICD4
function ends in
...
output <- comb.x
}
and not
...
output <- comb.x
output
}
there could be all sorts of weird behavior happening depending on the objects in your workspace?