On Sat, 11 Aug 2007, Ruddy M wrote:
> Hello,
> Q/ Is it possible to create a DBMS connection automatically on startup of
R? (Making sure of course that the db server has been started...)
> I am running MySQL on Mac OS X 10.4.2 with R2.4.1.
>
> I have tried to write a function using the RMySQL commands (below) and
place them in .First of .RProfile:
>
> drv <- dbDriver("MySQL")
> dbcon <- dbConnect(drv, {other parameters present in my.cnf file}
dbname="mydbName")
>
> DOES create a connection when entered into my R console individually but
NOT when I place them in a function, i.e.,
>
> condb <- function() {
> drv <- dbDriver("MySQL")
> dbcon <- dbConnect(drv, dbname="mydbName")
> dbGetInfo(db)
> }
>
> When the function is called, the dbGetInfo(dbcon) does return connection
> info but no connection object is present.
What do you think the return value of this function is?
You need to return dbcon, not the value of dbGetInfo(<some argument other
than db>). Perhaps you meant to print the latter?: if so you need at
explicit print() statement.
--
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