Thanks Josh - in my case I got it working now via
modifline='if ((profparam$mzcorrf!=1)&length(unique(rawdata$mz - trunc(rawdata$mz)))!=1) {rawdata$mz=rawdata$mz*profparam$mzcorrf} else if (profparam$mzcorrf!=1) {print("Exact masses were already rounded to nominal masses");profparam$mzcorrf=1}'
insertatline=6
trace(xcmsRaw, tracer=modifline,at=c(insertatline))
where I found the correct line to insert my modified code using
as.list(body(xcmsRaw))
To suppress the output of trace I then defined a second function
xcmsRaw2=function(...) {sink("NUL");obj=xcmsRaw(...);sink();return(obj) }
which can the be called and which does not provide any unnecessary tracing output.
Would still be nice to get it working via assignInNamespace() too though, as that would allow for more extensive edits/redefinitions and also for changes in the function arguments (which would be a common reason to redefine functions, that is, to take some extra argument)...