R called inside other applications
One thing that occasionally bothers me is how to refer a variable inside a function call, now it becomes more prominent when I try to use a parameter passed into a function from a RMySQL query. Here is the deal:
An example in RMySQL from RBlog
#Load the package library(RMySQL) # Set up a connection to your database management system. # I'm using the public MySQL server for the UCSC genome browser (no password) mychannel <- dbConnect(MySQL(), user="genome", host="genome-mysql.cse.ucsc.edu") # Function to make it easier to query query <- function(...) dbGetQuery(mychannel, ...) # Get the UCSC gene name, start and end sites for the first 10 genes on Chromosome 12 query("SELECT name, chrom, txStart, txEnd FROM mm9.knownGene WHERE chrom='chr12' LIMIT 10;")
My own database
mirList <- c("Adrenal", "Brainstem") numOfTis <- length(mirList) query <- function(...) dbGetQuery(mydb, ...) query("select rnMiR as mir, tissue as tis from TisSpeMiRs where tissue in (\"Adrenal\", \"Brainstem\") and ctrCode = 2 limit 2 ;") ## this works query("select rnMiR as mir, tissue as tis from TisSpeMiRs where tissue in eval(mirList) and ctrCode = 2 limit 2 ;") ## this does NOT work!!
Well, some “expert” posted Advanced R usage
Single quote vs. double quote is here
Learning step 1
Learning step 2