I used RODBC to connect to an Oracle XE hr schema. I needed a function that could return the number of records in a table. So that...
function(rodbcConnection, schemaName, tableName){ results <- sqlQuery(rodbcConnection, paste("SELECT * FROM ", schemaName, ".", tableName)) return(dim(results)[1]) }
But how to apply this to a table name vector? Here is how.
> x <- sapply(hrTableNames, noOfRecords, rodbcConnection=connection, schemaName="hr")
Because sapply does its job by applying the noOfRecords function to each row of hrTableNames, R replaces the missing tableName parameter with the current iterative value of hrTableNames.
At last.
> barplot(t(x), las=2)
Clarius Feb 23 '17 at 20:36 2017-02-23 20:36
source share