Re: [R] Connecting to database on statup

2007-08-11 Thread Prof Brian Ripley
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().  Perhaps you meant to print the latter?: if so you need at 
explicit print() statement.


-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch 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.


[R] Connecting to database on statup

2007-08-11 Thread Ruddy M
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.

I would be ver grateful for any guidance on where I have gone wrong. Thank you.

Mark Ruddy
PhD student
Geography Dept., Royal Holloway (University of London)
Egham, UK.


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.