Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove magritte dependency #370

Merged
merged 2 commits into from
Oct 25, 2024
Merged

Remove magritte dependency #370

merged 2 commits into from
Oct 25, 2024

Conversation

nmercadeb
Copy link
Collaborator

@nmercadeb nmercadeb commented Oct 23, 2024

All date operations work with clock functions except for this: https://github.com/OHDSI/CohortConstructor/blob/c82dbcc23e039a89450af71591db7fdec2d058e2/R/trimDemographics.R#L200C9-L206C11

I am not sure if it's just that I don't know how to do it, or if it is a bug? @edward-burn

library(duckdb)
#> Loading required package: DBI
library(here)
#> here() starts at C:/Users/nuriamb/AppData/Local/Temp/RtmpgpNqUU/reprex-886449ad49d3-loyal-rat
library(CDMConnector)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(DBI)
library(clock)
#> 
#> Attaching package: 'clock'
#> The following object is masked from 'package:CDMConnector':
#> 
#>     as_date

Sys.setenv(EUNOMIA_DATA_FOLDER = here())

con <- dbConnect(duckdb(), dbdir = eunomia_dir())
#> Downloading GiBleed
#> 
#> Download completed!
#> Creating CDM database
#> C:/Users/nuriamb/AppData/Local/Temp/RtmpgpNqUU/reprex-886449ad49d3-loyal-rat/GiBleed_5.3.zip

tableLocal <- tibble(date_col = as.Date(c("2000-01-01", "2000-01-02")), num_col = 1:2L)
tableLocal |>
  mutate(
    new_date_1 = add_days(.data$date_col, .data$num_col),
    new_date_2 = add_days(.data$date_col, 1:2)
  )
#> # A tibble: 2 × 4
#>   date_col   num_col new_date_1 new_date_2
#>   <date>       <int> <date>     <date>    
#> 1 2000-01-01       1 2000-01-02 2000-01-02
#> 2 2000-01-02       2 2000-01-04 2000-01-04

dbWriteTable(con, "table", tableLocal)

tableSQL <- tbl(con, sql("SELECT *FROM main.table")) 

tableSQL |>
  mutate(
    new_date_1 = add_days(.data$date_col, .data$num_col),
    new_date_2 = add_days(.data$date_col, 1:2)
  )
#> Error in `collect()`:
#> ! Failed to collect lazy table.
#> Caused by error:
#> ! rapi_execute: Failed to run query
#> Error: Conversion Error: Could not convert string 'num_col day' to INTERVAL

Created on 2024-10-23 with reprex v2.1.1

@nmercadeb nmercadeb marked this pull request as draft October 23, 2024 13:31
@nmercadeb nmercadeb linked an issue Oct 23, 2024 that may be closed by this pull request
@edward-burn
Copy link
Collaborator

@nmercadeb this needs to stay until the next release of dbplyr, but we could leave that and merge all the clean up you have done (and then when time comes it will be easy to remove the dependency on magrittr)

@nmercadeb nmercadeb marked this pull request as ready for review October 25, 2024 16:04
@edward-burn edward-burn merged commit 51ceaba into main Oct 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants