0

So I am passing in an argument to my R script. I then use the argument as part of my logic to name the SQL result table that I'm later going to fill and create with data. I first do the below and fill DestinationTable with the name of the table that I want.

DestinationTable <- paste("xx.TableName",args[4],sep = "")

After I do this I run a print(DestinationTable) and everything looks ok. Then when I do a sqlSave like the below it literally uses "DestinationTable" as the table name rather than the string I put into DestinationTable (such as "xx.TableNameArg4")

sqlSave(ch, data.frame(DestinationTable), rownames = FALSE)

How can I get the value stored in DestinationTable and use that rather than it using the literal word "DestinationTable"?

Thanks for any help!

1 Answer 1

3

I believe you misunderstand what happens when you write data.frame(DestinationTable). Let's see an example here:

> DestinationTable = "myTable"
> data.frame(DestinationTable)
  DestinationTable
1          myTable

Basically you get a data.frame object with a column called DestinationTable (your variable name) with a single row containing "myTable" (the variable value).

What you probably need to do is use the tablename parameter in sqlSave, as follows:

sqlSave(ch, data, tablename=DestinationTable)

This assumes there's a data.frame called 'data' with the actual data you want to write into the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.