It's because you're modifying the object in your function, not because of the type of the object. Passing an xts into myFunc provides the desired result
library(xts)
data(sample_matrix)
matrixObj=sample_matrix
xtsObj=as.xts(sample_matrix)
myFunc=function(data){
print(deparse(substitute(data)))
}
myFunc(xtsObj)
#[1] "matrixObj"
In addition, either using a different variable name for the xts object in your function or doing the coercion after getting the variable name would work:
library(xts)
data(sample_matrix)
matrixObj=sample_matrix
#use a different variable name for the xts object
myFunc3=function(data){
xtsdata=as.xts(data)
print(deparse(substitute(data)))
}
myFunc3(matrixObj)
#[1] "matrixObj"
#get the name before doing the coercion
myFunc4=function(data){
print(deparse(substitute(data)))
data=as.xts(data)
}
myFunc4(matrixObj)
#[1] "matrixObj"