You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After using as.character() in assignment the next chained assignment is unexpectedly slow. I couldn't find any other functions that this occurred with.
String conversions are expensive, therefore R delays them where possible in case the result isn't actually needed. The initial as.character call only produces what's known as an ALTREP object which in this case is essentially just a pointer to the original and a note to do the conversion next time the object is touched. Simply printing it is enough to trigger this conversion and data.table also forces the expansion any time you touch such an ALTREP column. This is what happens in the second example. If you replace that call with copy(df)[, x := as.character(x)][, x] you get the same effect. (The empty angle brackets do nothing btw.) So what you're observing is simply R taking some liberties with when it actually does what you asked.
After using
as.character()
in assignment the next chained assignment is unexpectedly slow. I couldn't find any other functions that this occurred with.The text was updated successfully, but these errors were encountered: