You've done a couple of things that are impermissible in R coding.
First, 2x is not a valid way to express multiplication. You must use 2 * x.
Second, if requires a single logical value. To do a conditional over a vector you must use either ifelse or indexing.
You may want to redefine k as
k <- function(x){
ifelse(x > 0, 2 * exp(-2 * x), 0)
}
Or, slightly more efficient, using indexing
k <- function(x){
positive <- x > 0
x[positive] <- 2 * exp(-2 * x[positive])
x[!positive] <- 0
x
}