Changing the df inside of the function does not change the testdf object outside of the function. You have to write the function so that it returns an object and assign that object to testdf.
DF <- data.frame(A = c(NA, 2), B = c(3, NA))
DF
#> A B
#> 1 NA 3
#> 2 2 NA
replaceNATest <- function(df, colName, value='Unknown') {
df[colName] <- ifelse( is.na(df[[colName]]), value, df[[colName]])
df
}
DF <- replaceNATest(DF, "A")
DF
#> A B
#> 1 Unknown 3
#> 2 2 NA
Created on 2019-11-08 by the reprex package (v0.3.0.9000)
Try running these two little blocks of code and you will see that A and x in the global environment are not affected by what goes on in MyFunc, which has its own environment.
MyFunc <- function(x) {
x <- x + 2
x
}
A = 6
MyFunc(A)
A
x = 3
MyFunc(x)
x