[R] dbWriteTable with row.names=(TRUE | FALSE)

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 8 22:44:37 CEST 2008


This is a bug that we've seen before.  It looks like this line of 
mysqlWriteTable

    if(missing(field.types) || is.null(field.types)){
       ## the following mapping should be coming from some kind of table
       ## also, need to use converter functions (for dates, etc.)
       field.types <- sapply(value, dbDataType, dbObj = con)
    }

since field.types is documented as

field.types: a list specifying the mapping from R/S-Plus fields in the
           data.frame 'value' to SQL data types.  The default is
           'sapply(value,SQLDataType)', see 'MySQLSQLType'.

OK, so it is a list but sapply is not usually returning a list!

I am Cc:ing the maintainer.  For now, I suggest replacing sapply by 
lapply.


On Fri, 8 Aug 2008, Hansruedi Baetschmann wrote:

> Hello
>
> Saving a dataframe with dbWriteTable to a relational database with the 
> parameter row.names set to FALSE works fine, doing so the parameter set to 
> TRUE gives an error message "/Fehler in field.types$row.names : $ operator is 
> invalid for atomic vectors/"  (see the protocol below).
>
> I work with R Ver.2.7.1
>
> What am I doing wrong ?
>
> Thanks
>
> Hansruedi Baetschmann
> ----------------------------------------------------------------------- 
> dipl.math.ETH et.lic.oec.HSG
> Functional Genomics Center Zurich
> Winterthurerstrasse 190 / Y32H66
> CH-8057 Zürich
> -----------------------------------------------------------------------
>
>> library("RMySQL")
>> con=dbConnect("MySQL",dbname="dataframes",user="root", 
> password="xxxxx",host="localhost" )
>> dbGetInfo(con)
> ...
> $serverVersion
> [1] "5.0.24-community-nt-log"
> $protocolVersion
> [1] 10
> ...
>> dbListTables(con)
> character(0)
>> df1=data.frame(a=c(1,2,3,4),b=c("a","b","c","d"))
>> df1
> a b
> 1 1 a
> 2 2 b
> 3 3 c
> 4 4 d
>> dbWriteTable(con,"df1_without_rownames",df1,row.names=FALSE)
> [1] TRUE
>> dbListTables(con)
> [1] "df1_without_rownames"
>> dbWriteTable(con,"df1_with_rownames",df1,row.names=TRUE)
> Fehler in field.types$row.names : $ operator is invalid for atomic vectors
>
> --------------------------------------------------------------------end
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list