Skip to content

Commit

Permalink
Fix R CMD check NOTEs
Browse files Browse the repository at this point in the history
Fixes #1461
  • Loading branch information
hadley committed Feb 21, 2024
1 parent 66f336d commit a9ad282
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions R/backend-mssql.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,13 @@ simulate_mssql <- function(version = "15.0") {
sql_expr(DATEFROMPARTS(!!year, !!month, !!day))
},
get_year = function(x) {
sql_expr(DATEPART('year', !!x))
sql_expr(DATEPART(YEAR, !!x))
},
get_month = function(x) {
sql_expr(DATEPART('month', !!x))
sql_expr(DATEPART(MONTH, !!x))
},
get_day = function(x) {
sql_expr(DATEPART('day', !!x))
sql_expr(DATEPART(DAY, !!x))
},

difftime = function(time1, time2, tz, units = "days") {
Expand All @@ -383,7 +383,7 @@ simulate_mssql <- function(version = "15.0") {
cli::cli_abort('The only supported value for {.arg units} on SQL backends is "days"')
}

sql_expr(DATEDIFF(day, !!time1, !!time2))
sql_expr(DATEDIFF(DAY, !!time1, !!time2))
}
)

Expand Down Expand Up @@ -659,4 +659,4 @@ bit_to_boolean <- function(x_expr) {
}
}

utils::globalVariables(c("BIT", "CAST", "%AS%", "%is%", "convert", "DATE", "DATENAME", "DATEPART", "IIF", "NOT", "SUBSTRING", "LTRIM", "RTRIM", "CHARINDEX", "SYSDATETIME", "SECOND", "MINUTE", "HOUR", "DAY", "DAYOFWEEK", "DAYOFYEAR", "MONTH", "QUARTER", "YEAR", "BIGINT", "INT", "%AND%", "%BETWEEN%"))
utils::globalVariables(c("BIT", "CAST", "%AS%", "%is%", "convert", "DATE", "DATEADD", "DATEFROMPARTS", "DATEDIFF", "DATENAME", "DATEPART", "IIF", "NOT", "SUBSTRING", "LTRIM", "RTRIM", "CHARINDEX", "SYSDATETIME", "SECOND", "MINUTE", "HOUR", "DAY", "DAYOFWEEK", "DAYOFYEAR", "MONTH", "QUARTER", "YEAR", "BIGINT", "INT", "%AND%", "%BETWEEN%"))
2 changes: 1 addition & 1 deletion R/backend-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,4 @@ db_explain.OraConnection <- db_explain.Oracle
#' @export
db_supports_table_alias_with_as.OraConnection <- db_supports_table_alias_with_as.Oracle

utils::globalVariables(c("DATE", "CURRENT_TIMESTAMP", "TRUNC", "dbms_random.VALUE"))
utils::globalVariables(c("DATE", "CURRENT_TIMESTAMP", "TRUNC", "dbms_random.VALUE", "DATEDIFF", "CEIL", "NUMTODSINTERVAL"))
2 changes: 1 addition & 1 deletion R/backend-postgres.R
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,4 @@ db_col_types.PqConnection <- function(con, table, call) {
#' @export
db_col_types.PostgreSQL <- db_col_types.PqConnection

utils::globalVariables(c("strpos", "%::%", "%FROM%", "%ILIKE%", "DATE", "EXTRACT", "TO_CHAR", "string_agg", "%~*%", "%~%", "MONTH", "DOY", "DATE_TRUNC", "INTERVAL", "FLOOR", "WEEK"))
utils::globalVariables(c("strpos", "%::%", "%FROM%", "%ILIKE%", "DATE", "EXTRACT", "TO_CHAR", "string_agg", "%~*%", "%~%", "MONTH", "DOY", "DATE_TRUNC", "INTERVAL", "FLOOR", "WEEK", "make_date", "date_part"))
4 changes: 2 additions & 2 deletions R/backend-redshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sql_translation.RedshiftConnection <- function(con) {
cli::cli_abort('The only supported value for {.arg units} on SQL backends is "days"')
}

sql_expr(DATEDIFF(day, !!time1, !!time2))
sql_expr(DATEDIFF(DAY, !!time1, !!time2))
}
),
sql_translator(.parent = postgres$aggregate,
Expand Down Expand Up @@ -179,4 +179,4 @@ supports_window_clause.Redshift <- function(con) {
#' @export
supports_window_clause.RedshiftConnection <- supports_window_clause.Redshift

utils::globalVariables(c("REGEXP_REPLACE", "LAG", "LEAD", "LISTAGG", "float", "text"))
utils::globalVariables(c("REGEXP_REPLACE", "LAG", "LEAD", "LISTAGG", "float", "text", "DATE_PART"))
10 changes: 5 additions & 5 deletions R/backend-snowflake.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ sql_translation.Snowflake <- function(con) {
sql_expr(DATE_FROM_PARTS(!!year, !!month, !!day))
},
get_year = function(x) {
sql_expr(DATE_PART('year', !!x))
sql_expr(DATE_PART(YEAR, !!x))
},
get_month = function(x) {
sql_expr(DATE_PART('month', !!x))
sql_expr(DATE_PART(MONTH, !!x))
},
get_day = function(x) {
sql_expr(DATE_PART('day', !!x))
sql_expr(DATE_PART(DAY, !!x))
},

difftime = function(time1, time2, tz, units = "days") {
Expand All @@ -243,7 +243,7 @@ sql_translation.Snowflake <- function(con) {
cli::cli_abort('The only supported value for {.arg units} on SQL backends is "days"')
}

sql_expr(DATEDIFF(day, !!time1, !!time2))
sql_expr(DATEDIFF(DAY, !!time1, !!time2))
},
# LEAST / GREATEST on Snowflake will not respect na.rm = TRUE by default (similar to Oracle/Access)
# https://docs.snowflake.com/en/sql-reference/functions/least
Expand Down Expand Up @@ -355,4 +355,4 @@ snowflake_pmin_pmax_builder <- function(dot_1, dot_2, comparison){
glue_sql2(sql_current_con(), glue("COALESCE(IFF({dot_2} {comparison} {dot_1}, {dot_2}, {dot_1}), {dot_2}, {dot_1})"))
}

utils::globalVariables(c("%REGEXP%", "DAYNAME", "DECODE", "FLOAT", "MONTHNAME", "POSITION", "trim", "LENGTH"))
utils::globalVariables(c("%REGEXP%", "DAYNAME", "DECODE", "FLOAT", "MONTHNAME", "POSITION", "trim", "LENGTH", "DATE_FROM_PARTS", "DATE_PART"))
2 changes: 1 addition & 1 deletion R/backend-spark-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ simulate_spark_sql <- function() simulate_dbi("Spark SQL")
table
}

utils::globalVariables("regexp_replace")
utils::globalVariables(c("regexp_replace", "date_add", "add_months", "datediff"))
10 changes: 5 additions & 5 deletions tests/testthat/test-backend-mssql.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ test_that("custom clock functions translated correctly", {
expect_error(test_translate_sql(add_days(x, 1, "dots", "must", "be empty")))
expect_equal(test_translate_sql(date_build(2020, 1, 1)), sql("DATEFROMPARTS(2020.0, 1.0, 1.0)"))
expect_equal(test_translate_sql(date_build(year_column, 1L, 1L)), sql("DATEFROMPARTS(`year_column`, 1, 1)"))
expect_equal(test_translate_sql(get_year(date_column)), sql("DATEPART('year', `date_column`)"))
expect_equal(test_translate_sql(get_month(date_column)), sql("DATEPART('month', `date_column`)"))
expect_equal(test_translate_sql(get_day(date_column)), sql("DATEPART('day', `date_column`)"))
expect_equal(test_translate_sql(get_year(date_column)), sql("DATEPART(YEAR, `date_column`)"))
expect_equal(test_translate_sql(get_month(date_column)), sql("DATEPART(MONTH, `date_column`)"))
expect_equal(test_translate_sql(get_day(date_column)), sql("DATEPART(DAY, `date_column`)"))
})

test_that("difftime is translated correctly", {
local_con(simulate_mssql())
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))

expect_error(test_translate_sql(difftime(start_date, end_date, units = "auto")))
expect_error(test_translate_sql(difftime(start_date, end_date, tz = "UTC", units = "days")))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-backend-redshift.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ test_that("custom clock functions translated correctly", {

test_that("difftime is translated correctly", {
local_con(simulate_redshift())
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))

expect_error(test_translate_sql(difftime(start_date, end_date, units = "auto")))
expect_error(test_translate_sql(difftime(start_date, end_date, tz = "UTC", units = "days")))
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test-backend-snowflake.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ test_that("custom clock functions translated correctly", {
expect_error(test_translate_sql(add_days(x, 1, "dots", "must", "be empty")))
expect_equal(test_translate_sql(date_build(2020, 1, 1)), sql("DATE_FROM_PARTS(2020.0, 1.0, 1.0)"))
expect_equal(test_translate_sql(date_build(year_column, 1L, 1L)), sql("DATE_FROM_PARTS(`year_column`, 1, 1)"))
expect_equal(test_translate_sql(get_year(date_column)), sql("DATE_PART('year', `date_column`)"))
expect_equal(test_translate_sql(get_month(date_column)), sql("DATE_PART('month', `date_column`)"))
expect_equal(test_translate_sql(get_day(date_column)), sql("DATE_PART('day', `date_column`)"))
expect_equal(test_translate_sql(get_year(date_column)), sql("DATE_PART(YEAR, `date_column`)"))
expect_equal(test_translate_sql(get_month(date_column)), sql("DATE_PART(MONTH, `date_column`)"))
expect_equal(test_translate_sql(get_day(date_column)), sql("DATE_PART(DAY, `date_column`)"))
})

test_that("difftime is translated correctly", {
local_con(simulate_snowflake())
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(day, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date, units = "days")), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))
expect_equal(test_translate_sql(difftime(start_date, end_date)), sql("DATEDIFF(DAY, `start_date`, `end_date`)"))

expect_error(test_translate_sql(difftime(start_date, end_date, units = "auto")))
expect_error(test_translate_sql(difftime(start_date, end_date, tz = "UTC", units = "days")))
Expand Down

0 comments on commit a9ad282

Please sign in to comment.