I have my code written in R that gives me dataframe as an output. Now I want to insert dataframe that has multiple columns and rows in SQL table using some R code. For that purpose I connected my RStudio with SQL Server through ODBC package and used the following insert function. Actually the output of my R code works if I try to insert my output (dataframe) that has only one column with multiple rows, in one column at a time. For that purpose I was using the following code:
conn <-odbcConnect("database")
link=("https://www.ncbi.nlm.nih.gov/protein/?term=antimicrobial+peptides+AND+
(%221%22%5BSLEN%5D%3A+%22+50%22%5BSLEN%5D)")
AMPs<-read_html(html)
AMPs
protein_link_title<-AMPs %>% html_nodes(".title a")%>% html_text()
protein_link_title
title<- sqlQuery(conn,paste0("INSERT INTO AMPs(protein_link_title) VALUES('",
protein_link_title, "')"))
title`
This is the code I'm using and it is inserting the protein titles in column named "protein_link_title" which I created in SQL but this time I want to insert my R output (dataframe of multiple rows and columns), in multiple columns at once. I want to insert more VALUES in multiple columns of SQL table with R. Please help me with this. Thanks in advance.