inconsistent behaviour of c(...)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

inconsistent behaviour of c(...)

R devel mailing list


Greetings,

Running R 3.5.0 under Windows 7

typeof(c(1,"2")) yields "character" as expected. But in

d.f <- data.frame(C=c(1,"2"))

typeof(d.f$C) yields "integer".

Is this a bug?

Michael Meyer

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: inconsistent behaviour of c(...)

plangfelder
I think your character vector got converted to a factor. See ?options,
section stringsAsFactors:

     ‘stringsAsFactors’: The default setting for arguments of
          ‘data.frame’ and ‘read.table’.
The default is TRUE, so strings get converted to factors when building
data frames.

Set options(stringsAsFactors=FALSE) and try again.

Peter

On Fri, Jul 19, 2019 at 12:15 AM Michael Meyer via R-devel
<[hidden email]> wrote:

>
>
>
> Greetings,
>
> Running R 3.5.0 under Windows 7
>
> typeof(c(1,"2")) yields "character" as expected. But in
>
> d.f <- data.frame(C=c(1,"2"))
>
> typeof(d.f$C) yields "integer".
>
> Is this a bug?
>
> Michael Meyer
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: inconsistent behaviour of c(...)

Rui Barradas
Hello,

A way to see this is with ?class

# OP's code
typeof(c(1,"2")) # "character"

d.f <- data.frame(C=c(1,"2"))
typeof(d.f$C)    # "integer"

# And check the objects' classes
class(c(1,"2")) # "character"
class(d.f$C)    # "factor"


Hope this helps,

Rui Barradas


Às 08:19 de 19/07/19, Peter Langfelder escreveu:

> I think your character vector got converted to a factor. See ?options,
> section stringsAsFactors:
>
>       ‘stringsAsFactors’: The default setting for arguments of
>            ‘data.frame’ and ‘read.table’.
> The default is TRUE, so strings get converted to factors when building
> data frames.
>
> Set options(stringsAsFactors=FALSE) and try again.
>
> Peter
>
> On Fri, Jul 19, 2019 at 12:15 AM Michael Meyer via R-devel
> <[hidden email]> wrote:
>>
>>
>>
>> Greetings,
>>
>> Running R 3.5.0 under Windows 7
>>
>> typeof(c(1,"2")) yields "character" as expected. But in
>>
>> d.f <- data.frame(C=c(1,"2"))
>>
>> typeof(d.f$C) yields "integer".
>>
>> Is this a bug?
>>
>> Michael Meyer
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: inconsistent behaviour of c(...)

Rui Barradas
I forgot there is also ?mode.


mode(c(1,"2")) # "character"
mode(d.f$C)    # "numeric" (not "integer")


Rui Barradas

Às 11:54 de 19/07/19, Rui Barradas escreveu:

> Hello,
>
> A way to see this is with ?class
>
> # OP's code
> typeof(c(1,"2")) # "character"
>
> d.f <- data.frame(C=c(1,"2"))
> typeof(d.f$C)    # "integer"
>
> # And check the objects' classes
> class(c(1,"2")) # "character"
> class(d.f$C)    # "factor"
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 08:19 de 19/07/19, Peter Langfelder escreveu:
>> I think your character vector got converted to a factor. See ?options,
>> section stringsAsFactors:
>>
>>       ‘stringsAsFactors’: The default setting for arguments of
>>            ‘data.frame’ and ‘read.table’.
>> The default is TRUE, so strings get converted to factors when building
>> data frames.
>>
>> Set options(stringsAsFactors=FALSE) and try again.
>>
>> Peter
>>
>> On Fri, Jul 19, 2019 at 12:15 AM Michael Meyer via R-devel
>> <[hidden email]> wrote:
>>>
>>>
>>>
>>> Greetings,
>>>
>>> Running R 3.5.0 under Windows 7
>>>
>>> typeof(c(1,"2")) yields "character" as expected. But in
>>>
>>> d.f <- data.frame(C=c(1,"2"))
>>>
>>> typeof(d.f$C) yields "integer".
>>>
>>> Is this a bug?
>>>
>>> Michael Meyer
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Use of restricted c++ keywords as variable names in headers

Travers Ching
I was trying to use one of the headers in R_ext/, but had trouble.  I
determined that it was due to using restricted keywords as variable names.
So to load in the header, I needed to do this:

#define class klass
#define private krivate
#include <R_ext/Connections.h>
#undef class
#undef private

I know that the altrep.h header previously had the same issue, but was
fixed.  Could this be changed as well?

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel