New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setv() typeof coercion #498
Comments
Hi, thanks. But it’s again the same answer as your last issue: operations by reference can neither change the type nor length of a vector. To change the type the entire vector would need to be copied to a larger double vector of the same length, but this vector needs to be allocated and would need to be assigned to a name e.g. x or y etc. This is not an operations by reference. By reference means we simply access and modify data structures without changing anything in the way these are stored and referenced in computer memory. So what you are saying is expected. The digits are simply ignored because the integer vector cannot accommodate them. Note that in base R you get the same behavior e.g. x[1:8] <- 8.5 should remove the digit (at least I think this is also a by-reference operation). If not then <- is not by reference and this operation first copies x to a double vector and then does the replacement (which is very inefficient). |
Hi, suspected it was not possible (as I stated myself). That's why I asked if an error or warning could be produced when the user attempts to perform a replacement where the replacement PS: [<- is not by reference. It will coerce |
I don’t think a warning should be issued because this is the expected behavior, and the input could be cleanly coercible e.g. using 8 or 8.0 would work without loss of information. But I’ll think about it for a bit. |
OK. Btw, data.table::set() does give warnings, so it would be more consistent with data.table if collapse::setv() also gives warnings. |
Hi,
First of all: I enjoy the
collapse
package very much. Thank you for your efforts, it is greatly appreciated!Regarding my question/request...
Consider the following code:
What I would expect
x
to become isc(rep(8.5, 8), 9:16)
.But what I get is
c(rep(8, 8), 9:16)
.If I explictly set
as.double(x)
, this gets corrected.I get why this is: no
typeof
coercion takes place. But I can imagine the above situation can lead to problems, especially in large scripts.It would be nice if either setv() gives an Error or Warning when
R
andx
are not of the same type, or ifsetv()
allows for type coercion just like base R's[<-
method, though the latter might not be possible.Kind regards,
Tony.
The text was updated successfully, but these errors were encountered: