R programming: How to pass variables from a r program to mysql function?

0 votes

I am currently using R Programming and MySQL. I need to read the variables from R and pass those as inputs to a function in MySQL. 

options(echo=FALSE)
args <- commandArgs(trailingOnly=TRUE)
start.date <- as.Date(args[1])
end.date <- as.Date(args[2])
library(RMySQL)
mydb = dbConnect(mydb,xxxx)
rs <- dbSendQuery(mydb,"SELECT COMPUTE_WEEKS(start.date,end.date) FROM DUAL;")

I'm getting the following error:

rs <- dbSendQuery(mydb, "SELECT COMPUTE_WEEKS(start.date,end.date) FROM DUAL;") Error in .local(conn, statement, ...) : could not run statement: Unknown table 'start' in field list

Any help would be appreciated.

Dec 28, 2018 in Data Analytics by Sophie may
• 9,050 points
52 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

To include the R variables called start.date and end.date, you can use paste to build the query string:

query <- paste0("SELECT COMPUTE_WEEKS(", start.date, ", ", end.date, ") FROM DUAL;")
mydb <- dbConnect(mydb, xxxx)
rs <- dbSendQuery(mydb, query)
answered Dec 28, 2018 by Tyrion anex
• 8,280 points

Related Questions In Data Analytics

0 votes
1 answer

How to create dummy variables based on a categorical variable of lists in R?

You can use mtabulate in the following way: library(qdapTools) cbind(data[1], ...READ MORE

answered Apr 13, 2018 in Data Analytics by CodingByHeart77
• 3,680 points
309 views
0 votes
2 answers

How to remove NA values from a Vector in R?

data = data[!is.na(data)]\ READ MORE

answered Apr 5 in Data Analytics by anonymous
3,458 views
0 votes
1 answer

How to import data from a Json file into R?

Easy and simple: library("rjson") json_file <- "file_name" json_data <- fromJSON(file=json_file)) or ...READ MORE

answered Apr 26, 2018 in Data Analytics by DeepCoder786
• 1,700 points
89 views
0 votes
1 answer

Assigning global variables from inside a function - R

You can assign global variables from inside ...READ MORE

answered May 14, 2018 in Data Analytics by Bharani
• 4,550 points
35 views
0 votes
1 answer

R programming: How to compute Euler's number?

The following R statement exp(1) indicates e, and exp(2) represents e^2. This ...READ MORE

answered Dec 28, 2018 by Tyrion anex
• 8,280 points
32 views
0 votes
1 answer

R Programming: Implement Newton Raphson Algorithm

The problem is that the expressions for f and f1 ...READ MORE

answered Jan 7 in Data Analytics by Tyrion anex
• 8,280 points
102 views
0 votes
1 answer

R programming: Flip coin simulation

Make use of the ggplot2 package. Start by installing and ...READ MORE

answered Jan 21 in Data Analytics by Sophie may
• 9,050 points
44 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,700 points
23 views
0 votes
1 answer

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
47 views
0 votes
1 answer

R programming: How to convert Tiff to IMG (ERDAS) format?

This code should work: library(raster) input <- list.files(pattern='tif$') output <- ...READ MORE

answered Jan 16 in Data Analytics by Tyrion anex
• 8,280 points
50 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.