You try to assign by name a global variable within a function. Why? Should avoid to manipulate global variable and as said in the comment should exist better manner to deal with your problem and avoid global variable side effect.
You should use assign
to change value by name. By default, it changes value in the current environment(local), So you should also set in which environment your variable is defined. Something like this :
assign( x , as.matrix(get(x)),envir=.GlobalEnv)
Or , tell assign
to search until it encounters the variable :
assign( x , as.matrix(get(x)),inherits=TRUE)
EDIT better solution
Return the new value and assign it later in the global environment
assign( x , function(x){....})
If the variable is kind of global setting you can define an environment where your define myvector.
myoptions <- new.env() myoptions$myvalue <- 1:5 function(x){ assign(x,newvalue,myoptions )}