I am updating a set of functions that previously only data.frame objects for working with data.table arguments.
I decided to implement this function by sending the R method, so that the old code using data.frame still work with the updated functions. In one of my functions, I take as input data.frame as input, modify it and return the modified data.frame . I created an implementation of data.table . For instance:
# The functions foo <- function(d) { UseMethod("foo") } foo.data.frame <- function(d) { <Do Something> return(d) } foo.data.table <- function(d) { <Do Something> return(d) }
I know that data.table works by making changes without copying, and I implemented foo.data.table , keeping this in mind. However, I am returning the data.table object at the end of the function because I want my old scripts to work with the new data.table objects. Will it make a copy of data.table ? How can i check? According to the documentation, to create a copy of data.table you need to be very explicit, but I'm not sure about this.
The reason I want to return something when I don't need with data.tables :
My old scripts look like this:
someData <- read.table(...) ... someData <- foo(someData)
I want the scripts to be able to work with data.table , just by changing the data receiving lines. In other words, I want the script to work just by changing someData <- read.table(...) to someData <- fread(...) .
source share