dbplyr

postgres generate array using slide window

╄→гoц情女王★ 提交于 2021-02-10 14:41:09
问题 I'm trying to figure out how to a query to generate an ARRAY given a sliding window over a character column with Postgre. For example, if I have this: pid <chr> 1 WP_096038768.1 2 WP_013465871.1 3 WP_058155244.1 4 WP_011329269.1 5 WP_058374608.1 6 WP_089368983.1 7 WP_096739105.1 8 WP_089346667.1 9 WP_096041177.1 10 WP_010553306.1 ... I want a sliding window of size 1 before and after the row. The result is this: pid g <chr> <chr> 1 WP_013465871.1 WP_096038768.1,WP_013465871.1,WP_058155244.1 2

How to use custom SQL function in dbplyr?

て烟熏妆下的殇ゞ 提交于 2021-02-07 03:51:30
问题 I would like to calculate the Jaro-Winkler string distance in a database. If I bring the data into R (with collect ) I can easily use the stringdist function from the stringdist package. But my data is very large and I'd like to filter on Jaro-Winkler distances before pulling the data into R. There is SQL code for Jaro-Winkler (https://androidaddicted.wordpress.com/2010/06/01/jaro-winkler-sql-code/ and a version for T-SQL) but I guess I'm not sure how best to get that SQL code to work with

How to use custom SQL function in dbplyr?

只谈情不闲聊 提交于 2021-02-07 03:45:22
问题 I would like to calculate the Jaro-Winkler string distance in a database. If I bring the data into R (with collect ) I can easily use the stringdist function from the stringdist package. But my data is very large and I'd like to filter on Jaro-Winkler distances before pulling the data into R. There is SQL code for Jaro-Winkler (https://androidaddicted.wordpress.com/2010/06/01/jaro-winkler-sql-code/ and a version for T-SQL) but I guess I'm not sure how best to get that SQL code to work with

Filter data frame in Shiny app

怎甘沉沦 提交于 2021-01-28 09:49:07
问题 I'm trying to filter a data frame with user input as radio buttons. Unfortunately, only one type of filter works (the "Annual" version in my example), but the "Monthly" and "Quarterly" options are not returning anything. Here is my sample data set and code. # sample data mydf <- data.frame("Data"=rnorm(12), "Months"=c("Jan", "Nov", "Dec", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct")) library(shiny) library(dbplyr) ui <- fluidPage( # Input() function radioButtons(inputId =

How to join tables from different SQL databases using R and dplyr?

痞子三分冷 提交于 2020-12-05 05:00:25
问题 I'm using dplyr (0.7.0) , dbplyr (1.0.0) , DBI 0.6-1 , and odbc (1.0.1.9000) . I would like to do something like the following: db1 <- DBI::dbConnect( odbc::odbc(), Driver = "SQL Server", Server = "MyServer", Database = "DB1" ) db2 <- DBI::dbConnect( odbc::odbc(), Driver = "SQL Server", Server = "MyServer", Database = "DB2" ) x <- tbl(db1, "Table1") %>% dplyr::left_join(tbl(db2, "Table2"), by = "JoinColumn") but I keep getting an error that doesn't really seem to have any substance to it.

How to pipe SQL into R's dplyr?

*爱你&永不变心* 提交于 2020-08-07 05:28:24
问题 I can use the following code in R to select distinct rows in any generic SQL database. I'd use dplyr::distinct() but it's not supported in SQL syntax. Anyways, this does indeed work: dbGetQuery(database_name, "SELECT t.* FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) AS SEQNUM FROM table_name t ) t WHERE SEQNUM = 1;") I've been using it with success, but wonder how I can pipe that same SQL query after other dplyr steps, as opposed to just using it as a

How to pipe SQL into R's dplyr?

北城余情 提交于 2020-08-07 05:28:02
问题 I can use the following code in R to select distinct rows in any generic SQL database. I'd use dplyr::distinct() but it's not supported in SQL syntax. Anyways, this does indeed work: dbGetQuery(database_name, "SELECT t.* FROM (SELECT t.*, ROW_NUMBER() OVER (PARTITION BY column_name ORDER BY column_name) AS SEQNUM FROM table_name t ) t WHERE SEQNUM = 1;") I've been using it with success, but wonder how I can pipe that same SQL query after other dplyr steps, as opposed to just using it as a

Using ODBC::dbConnect and dplyr to connect to Sybase IQ database - table name not found

半世苍凉 提交于 2020-07-08 03:41:27
问题 I can connect to my Sybase IQ 16 database using a connection string such as: myDB_conn <- dbConnect(odbc(), "MyDSN_Name") When I run this command the connections view shows a list of databases and corresponding tables/views. However when I try to use the logic laid out here specifically naming the view I keep receiving an error about my view not being found. test <- tbl(myDB_conn, "OFFSHORE_BOB.SOME_VIEW_OR_TABLE_NAME") In the connection window I can see the database and view but when I use

Function that composes functions with existing sql translations in dbplyr

纵然是瞬间 提交于 2020-05-23 06:30:07
问题 This question arises because I wish to make a function for my convenience: as.numeric_psql <- function(x) { return(as.numeric(as.integer(x))) } to convert boolean values in a remote postgres table into numeric. The step to convert to integer is needed as: There is no direct cast defined between numeric and boolean. You can use integer as middle-ground. (https://stackoverflow.com/a/19290671/2109289) Of course this function works as expected locally: copy_to(con_psql, cars, 'tmp_cars') tmp_cars

R: Best Practices - dplyr and odbc multi table actions (retrieved from SQL)

独自空忆成欢 提交于 2020-05-13 06:59:45
问题 Say you have your tables stores in an SQL server DB, and you want to perform multi table actions, i.e. join several tables from that same database. Following code can interact and receive data from SQL server: library(dplyr) library(odbc) con <- dbConnect(odbc::odbc(), .connection_string = "Driver={SQL Server};Server=.;Database=My_DB;") Table1 <- tbl(con, "Table1") Table1 # View glimpse of Table1 Table2 <- tbl(con, "Table2") Table2 # View glimpse of Table2 Table3 <- tbl(con, "Table3") However