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
• 10,620 points
1,343 views

1 answer to this question.

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,700 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,750 points
2,634 views
+1 vote
5 answers

How to remove NA values from a Vector in R?

Hello team, you can use na.omit x <- c(NA, 3, ...READ MORE

answered Dec 9, 2020 in Data Analytics by anonymous
• 82,840 points
195,264 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,720 points
2,379 views
0 votes
1 answer

Assigning global variables from inside a function - R

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

answered May 15, 2018 in Data Analytics by Bharani
• 4,660 points
11,019 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,700 points
1,518 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, 2019 in Data Analytics by Tyrion anex
• 8,700 points
1,612 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, 2019 in Data Analytics by Sophie may
• 10,620 points
1,261 views
0 votes
1 answer

How to edit the labels and limit if a plot using ggplot? - R

Add a limit to axis ticks using ...READ MORE

answered Nov 3, 2019 in Data Analytics by anonymous
• 33,030 points
720 views
+1 vote
3 answers

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$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,845 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, 2019 in Data Analytics by Tyrion anex
• 8,700 points
1,422 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP