ok. I tested it in two ways. I want to externalise my odbcConnection details dsn, uid, and pwd. Hence I created a csv file to have these information. Like I showed in the sample function initially, the order of the steps were 1) loading of the packages, 2) fetching the csv file, 3)assigning the dsn, uid, and pwd separately to values, 4) establish the connection by using these values .
The sample function I created thus was: fun <- function () { # Package load into R; a <- c(library("RODBC"),library("e1071")); b <- read.csv("path of the csv file", header=TRUE, sep=",", quote=""); c<- b[,1]; d <- b[,2]; e<- b[,3]; rm(b); # Establishing ODBC connection; connection <- odbcConnect(c, uid=d, pwd=e); X<-list(a=a, b=b, c=c,d=d, e=e, connection=connection); return(X); } # function call > fun() Error in RegressionAnalytics() : object 'b' not found In addition: Warning messages: 1: package 'RODBC' was built under R version 2.13.1 2: package 'e1071' was built under R version 2.13.1 However, when I simply give the code for fetch directly on the command prompt, it works. > b <- read.csv("path of the csv file", header=TRUE, sep=",", > quote=""); object b gets created under data. I checked the path of the file and its name. They are correct. So I thought I'll directly give the dsn, uid, and pwd information in odbcConnection instead of externalizing it to see how the function responds. This is what I did: > fun <- function() { a <- c(library("RODBC"),library("e1071")); connection <- odbcConnect("x",uid="xy",pwd="abcdef"); X<-list(b=b,connection=connection); return(X); } # function call and result > fun () $a [1] "e1071" "RODBC" "class" "stats" "graphics" [7] "grDevices" "utils" "datasets" "methods" "base" [13] "e1071" "RODBC" "class" "stats" "graphics" "grDevices" [19] "utils" "datasets" "methods" "base" "e1071" [25] "RODBC" "class" "stats" "graphics" "grDevices" "utils" [31] "datasets" "methods" "base" $connection RODBC Connection 4 Details: case=nochange DSN=x Description=test UID=xy PWD=****** APP=RStudio when I try to see the connection object by typing in the command prompt it throws an error saying the object is not found: > connection Error: object 'connection' not found This is what I meant by the function being created, printed but object not created. I should also mention that these steps run perfectly fine when not assigned to a function (both the methods). So i guess the code is ok. I am missing something but am not able to figure that out. By the looks of it I think I have assigned the values to be returned to some object. Any thoughts? Thanks Divya -- View this message in context: http://r.789695.n4.nabble.com/Problem-executing-function-tp3894359p3897639.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@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.