Bug 17344 - After x <- numeric(0); x[logical(0)] <- character(0) , x is not coerced
Summary: After x <- numeric(0); x[logical(0)] <- character(0) , x is not coerced
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.3.*
Hardware: All All
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-09-23 09:53 UTC by Suharto Anggono
Modified: 2017-09-23 09:53 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Suharto Anggono 2017-09-23 09:53:07 UTC
From "Details" section in Extract.Rd :
When an index expression appears on the left side of an assignment (known as subassignment) then that part of x is set to the value of the right hand side of the assignment.  In this case no partial matching of character indices is done, and the left-hand-side is coerced as needed to accept the values.  For vectors, the answer will be of the higher of the types of x and value in the hierarchy raw < logical < integer < double < complex < character < list < expression.


Example from Bug 17200 Comment 5:
mmm <- numeric(0)
mmm[logical(0)] <- character(0)
mmm

Output:
numeric(0)

Expected output:
character(0)

I expect that 'mmm' will be coerced to character.


Example from Bug 17200 Comment 6, that gives the result that I expect:
mmm <- numeric(0)
mmm[logical(0)] <- ""
mmm

Output:
character(0)


It seems that this part of function 'do_subassign_dflt' in subassign.c gives the effect.
    else if (xlength(x) == 0) {
	if (xlength(y) == 0) {
	    UNPROTECT(1);
	    return(x);
	}

It is still like that in R devel r73338.