diff --git a/NEWS.md b/NEWS.md index bccd13cd5..d31b3d584 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ - New method `$clone()` for `LazyFrame` (#347). - `$with_column()` is now deprecated (following upstream `polars`). It will be removed in 0.9.0. It should be replaced with `$with_columns()` (#313). +- New lazy function translated: `concat_str()` to concatenate several columns + into one (#349). - New stat functions `pl$cov()`, `pl$rolling_cov()` `pl$corr()`, `pl$rolling_corr()` (#351). # polars 0.7.0 diff --git a/R/dataframe__frame.R b/R/dataframe__frame.R index 3826d2ae5..46f5e3e0a 100644 --- a/R/dataframe__frame.R +++ b/R/dataframe__frame.R @@ -1003,13 +1003,13 @@ DataFrame_to_list = function(unnest_structs = TRUE) { #' @keywords DataFrame #' @examples #' # inner join by default -#' df1 <- pl$DataFrame(list(key = 1:3, payload = c("f", "i", NA))) -#' df2 <- pl$DataFrame(list(key = c(3L, 4L, 5L, NA_integer_))) +#' df1 = pl$DataFrame(list(key = 1:3, payload = c("f", "i", NA))) +#' df2 = pl$DataFrame(list(key = c(3L, 4L, 5L, NA_integer_))) #' df1$join(other = df2, on = "key") #' #' # cross join -#' df1 <- pl$DataFrame(x = letters[1:3]) -#' df2 <- pl$DataFrame(y = 1:4) +#' df1 = pl$DataFrame(x = letters[1:3]) +#' df2 = pl$DataFrame(y = 1:4) #' df1$join(other = df2, how = "cross") #' DataFrame_join = function( @@ -1560,7 +1560,6 @@ DataFrame_glimpse = function(..., return_as_string = FALSE) { #' df #' #' df$explode("numbers") - DataFrame_explode = function(columns, ...) { self$lazy()$explode(columns, ...)$collect() } diff --git a/R/expr__expr.R b/R/expr__expr.R index 370b9bb53..063e740e2 100644 --- a/R/expr__expr.R +++ b/R/expr__expr.R @@ -3322,7 +3322,7 @@ Expr_diff = function(n = 1, null_behavior = "ignore") { #' @keywords Expr #' @examples #' df = pl$DataFrame(list(a = c(10L, 11L, 12L, NA_integer_, 12L))) -#' df$with_column(pl$col("a")$pct_change()$alias("pct_change")) +#' df$with_columns(pl$col("a")$pct_change()$alias("pct_change")) Expr_pct_change = function(n = 1) { unwrap(.pr$Expr$pct_change(self, n)) } @@ -3417,7 +3417,7 @@ Expr_kurtosis = function(fisher = TRUE, bias = TRUE) { #' #' @examples #' df = pl$DataFrame(foo = c(-50L, 5L, NA_integer_, 50L)) -#' df$with_column(pl$col("foo")$clip(1L, 10L)$alias("foo_clipped")) +#' df$with_columns(pl$col("foo")$clip(1L, 10L)$alias("foo_clipped")) Expr_clip = function(min, max) { unwrap(.pr$Expr$clip(self, wrap_e(min), wrap_e(max))) } @@ -3427,7 +3427,7 @@ Expr_clip = function(min, max) { #' @aliases clip_min #' @keywords Expr #' @examples -#' df$with_column(pl$col("foo")$clip_min(1L)$alias("foo_clipped")) +#' df$with_columns(pl$col("foo")$clip_min(1L)$alias("foo_clipped")) Expr_clip_min = function(min) { unwrap(.pr$Expr$clip_min(self, wrap_e(min))) } @@ -3437,7 +3437,7 @@ Expr_clip_min = function(min) { #' @aliases clip_max #' @keywords Expr #' @examples -#' df$with_column(pl$col("foo")$clip_max(10L)$alias("foo_clipped")) +#' df$with_columns(pl$col("foo")$clip_max(10L)$alias("foo_clipped")) Expr_clip_max = function(max) { unwrap(.pr$Expr$clip_max(self, wrap_e(max))) } @@ -4182,7 +4182,7 @@ Expr_list = function() { #' f = c("a", "b", "c"), #' g = c(0.1, 1.32, 0.12), #' h = c(TRUE, NA, FALSE) -#' )$with_column(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype()) +#' )$with_columns(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype()) Expr_shrink_dtype = "use_extendr_wrapper" @@ -4204,7 +4204,7 @@ Expr_shrink_dtype = "use_extendr_wrapper" #' )$agg( #' pl$col("value") * 3L #' ) -#' df_with_list$with_column( +#' df_with_list$with_columns( #' pl$col("value")$arr$lengths()$alias("group_size") #' ) Expr_arr = method_as_property(function() { diff --git a/R/expr__list.R b/R/expr__list.R index 72985bf64..8b9ee52d8 100644 --- a/R/expr__list.R +++ b/R/expr__list.R @@ -17,7 +17,7 @@ #' @aliases lengths arr.lengths arr_lengths #' @examples #' df = pl$DataFrame(list_of_strs = pl$Series(list(c("a", "b"), "c"))) -#' df$with_column(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths")) +#' df$with_columns(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths")) ExprArr_lengths = function() .pr$Expr$arr_lengths(self) #' Sum lists @@ -415,7 +415,7 @@ ExprArr_to_struct = function( #' @aliases arr_eval arr.eval #' @examples #' df = pl$DataFrame(a = list(c(1, 8, 3), b = c(4, 5, 2))) -#' df$select(pl$all()$cast(pl$dtypes$Int64))$with_column( +#' df$select(pl$all()$cast(pl$dtypes$Int64))$with_columns( #' pl$concat_list(c("a", "b"))$arr$eval(pl$element()$rank())$alias("rank") #' ) ExprArr_eval = function(expr, parallel = FALSE) { diff --git a/R/extendr-wrappers.R b/R/extendr-wrappers.R index 04973aa1c..8f9f45e44 100644 --- a/R/extendr-wrappers.R +++ b/R/extendr-wrappers.R @@ -35,6 +35,8 @@ sum_exprs <- function(exprs) .Call(wrap__sum_exprs, exprs) concat_list <- function(exprs) .Call(wrap__concat_list, exprs) +concat_str <- function(dotdotdot, separator) .Call(wrap__concat_str, dotdotdot, separator) + r_date_range <- function(start, stop, every, closed, name, tu, tz) .Call(wrap__r_date_range, start, stop, every, closed, name, tu, tz) r_date_range_lazy <- function(start, end, every, closed, tz) .Call(wrap__r_date_range_lazy, start, end, every, closed, tz) diff --git a/R/functions__lazy.R b/R/functions__lazy.R index c19c48151..6ea9e8650 100644 --- a/R/functions__lazy.R +++ b/R/functions__lazy.R @@ -529,12 +529,12 @@ pl$approx_unique = function(column) { #-> int or Expr #' df = pl$DataFrame(a = 1:2, b = 3:4, c = 5:6) #' #' # column as list -#' df$with_column(pl$sum(list("a", "c"))) -#' df$with_column(pl$sum(list("a", "c", 42L))) +#' df$with_columns(pl$sum(list("a", "c"))) +#' df$with_columns(pl$sum(list("a", "c", 42L))) #' #' # two eqivalent lines -#' df$with_column(pl$sum(list(pl$col("a") + pl$col("b"), "c"))) -#' df$with_column(pl$sum(list("*"))) +#' df$with_columns(pl$sum(list(pl$col("a") + pl$col("b"), "c"))) +#' df$with_columns(pl$sum(list("*"))) pl$sum = function(...) { column = list2(...) if (length(column) == 1L) column <- column[[1L]] @@ -576,7 +576,7 @@ pl$sum = function(...) { #' d = c(1:2, NA_real_, -Inf) #' ) #' # use min to get first non Null value for each row, otherwise insert 99.9 -#' df$with_column( +#' df$with_columns( #' pl$min("a", "b", "c", 99.9)$alias("d") #' ) #' @@ -623,7 +623,7 @@ pl$min = function(...) { #' c = c(1:3, NA_real_) #' ) #' # use coalesce to get first non Null value for each row, otherwise insert 99.9 -#' df$with_column( +#' df$with_columns( #' pl$coalesce("a", "b", "c", 99.9)$alias("d") #' ) #' @@ -669,7 +669,7 @@ pl$max = function(...) { #' c = c(1:3, NA_real_) #' ) #' # use coalesce to get first non Null value for each row, otherwise insert 99.9 -#' df$with_column( +#' df$with_columns( #' pl$coalesce("a", "b", "c", 99.9)$alias("d") #' ) #' @@ -845,6 +845,36 @@ pl$struct = function( ) } +#' Horizontally concatenate columns into a single string column +#' +#' @param ... Columns to concatenate into a single string column. Accepts +#' expressions. Strings are parsed as column names, other non-expression inputs +#' are parsed as literals. Non-Utf8 columns are cast to Utf8. +#' @param separator String that will be used to separate the values of each +#' column. +#' @name pl_concat_str +#' @return Expr +#' @examples +#' df = pl$DataFrame( +#' a = c(1, 2, 3), +#' b = c("dogs", "cats", NA), +#' c = c("play", "swim", "walk") +#' ) +#' +#' df$with_columns( +#' pl$concat_str( +#' pl$col("a") * 2, +#' "b", +#' "c", +#' pl$lit("!"), +#' separator = " " +#' )$alias("full_sentence") +#' ) +#' +pl$concat_str = function(..., separator = "") { + concat_str(list2(...), separator) |> unwrap("in $concat_str()") +} + #' Covariance #' @name pl_cov #' @description Calculates the covariance between two columns / expressions. diff --git a/man/DataFrame_join.Rd b/man/DataFrame_join.Rd index 86572e40c..151aaf708 100644 --- a/man/DataFrame_join.Rd +++ b/man/DataFrame_join.Rd @@ -40,13 +40,13 @@ join DataFrame with other DataFrame } \examples{ # inner join by default -df1 <- pl$DataFrame(list(key = 1:3, payload = c("f", "i", NA))) -df2 <- pl$DataFrame(list(key = c(3L, 4L, 5L, NA_integer_))) +df1 = pl$DataFrame(list(key = 1:3, payload = c("f", "i", NA))) +df2 = pl$DataFrame(list(key = c(3L, 4L, 5L, NA_integer_))) df1$join(other = df2, on = "key") # cross join -df1 <- pl$DataFrame(x = letters[1:3]) -df2 <- pl$DataFrame(y = 1:4) +df1 = pl$DataFrame(x = letters[1:3]) +df2 = pl$DataFrame(y = 1:4) df1$join(other = df2, how = "cross") } diff --git a/man/Expr_arr.Rd b/man/Expr_arr.Rd index bc9119e89..027fedd15 100644 --- a/man/Expr_arr.Rd +++ b/man/Expr_arr.Rd @@ -24,7 +24,7 @@ df_with_list = pl$DataFrame( )$agg( pl$col("value") * 3L ) -df_with_list$with_column( +df_with_list$with_columns( pl$col("value")$arr$lengths()$alias("group_size") ) } diff --git a/man/Expr_clip.Rd b/man/Expr_clip.Rd index 5aa41983f..92698d4e4 100644 --- a/man/Expr_clip.Rd +++ b/man/Expr_clip.Rd @@ -33,8 +33,8 @@ expression. See :func:\code{when} for more information. } \examples{ df = pl$DataFrame(foo = c(-50L, 5L, NA_integer_, 50L)) -df$with_column(pl$col("foo")$clip(1L, 10L)$alias("foo_clipped")) -df$with_column(pl$col("foo")$clip_min(1L)$alias("foo_clipped")) -df$with_column(pl$col("foo")$clip_max(10L)$alias("foo_clipped")) +df$with_columns(pl$col("foo")$clip(1L, 10L)$alias("foo_clipped")) +df$with_columns(pl$col("foo")$clip_min(1L)$alias("foo_clipped")) +df$with_columns(pl$col("foo")$clip_max(10L)$alias("foo_clipped")) } \keyword{Expr} diff --git a/man/Expr_pct_change.Rd b/man/Expr_pct_change.Rd index 15df8041e..b8c04c91f 100644 --- a/man/Expr_pct_change.Rd +++ b/man/Expr_pct_change.Rd @@ -21,6 +21,6 @@ Computes the change from the previous row by default. } \examples{ df = pl$DataFrame(list(a = c(10L, 11L, 12L, NA_integer_, 12L))) -df$with_column(pl$col("a")$pct_change()$alias("pct_change")) +df$with_columns(pl$col("a")$pct_change()$alias("pct_change")) } \keyword{Expr} diff --git a/man/Expr_shrink_dtype.Rd b/man/Expr_shrink_dtype.Rd index 2dda08465..c205ea542 100644 --- a/man/Expr_shrink_dtype.Rd +++ b/man/Expr_shrink_dtype.Rd @@ -24,6 +24,6 @@ pl$DataFrame( f = c("a", "b", "c"), g = c(0.1, 1.32, 0.12), h = c(TRUE, NA, FALSE) -)$with_column(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype()) +)$with_columns(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype()) } \keyword{Expr} diff --git a/man/arr_eval.Rd b/man/arr_eval.Rd index a7a0c3852..14d43edae 100644 --- a/man/arr_eval.Rd +++ b/man/arr_eval.Rd @@ -25,7 +25,7 @@ Run any polars expression against the lists' elements. } \examples{ df = pl$DataFrame(a = list(c(1, 8, 3), b = c(4, 5, 2))) -df$select(pl$all()$cast(pl$dtypes$Int64))$with_column( +df$select(pl$all()$cast(pl$dtypes$Int64))$with_columns( pl$concat_list(c("a", "b"))$arr$eval(pl$element()$rank())$alias("rank") ) } diff --git a/man/arr_lengths.Rd b/man/arr_lengths.Rd index a6a50e778..fcc138646 100644 --- a/man/arr_lengths.Rd +++ b/man/arr_lengths.Rd @@ -16,6 +16,6 @@ Get the length of the arrays as UInt32 } \examples{ df = pl$DataFrame(list_of_strs = pl$Series(list(c("a", "b"), "c"))) -df$with_column(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths")) +df$with_columns(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths")) } \keyword{ExprArr} diff --git a/man/pl_coalesce.Rd b/man/pl_coalesce.Rd index 66c521ed1..9ea56fc05 100644 --- a/man/pl_coalesce.Rd +++ b/man/pl_coalesce.Rd @@ -28,7 +28,7 @@ df = pl$DataFrame( c = c(1:3, NA_real_) ) # use coalesce to get first non Null value for each row, otherwise insert 99.9 -df$with_column( +df$with_columns( pl$coalesce("a", "b", "c", 99.9)$alias("d") ) diff --git a/man/pl_concat_str.Rd b/man/pl_concat_str.Rd new file mode 100644 index 000000000..5999332fa --- /dev/null +++ b/man/pl_concat_str.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/functions__lazy.R +\name{pl_concat_str} +\alias{pl_concat_str} +\title{Horizontally concatenate columns into a single string column} +\arguments{ +\item{...}{Columns to concatenate into a single string column. Accepts +expressions. Strings are parsed as column names, other non-expression inputs +are parsed as literals. Non-Utf8 columns are cast to Utf8.} + +\item{separator}{String that will be used to separate the values of each +column.} +} +\value{ +Expr +} +\description{ +Horizontally concatenate columns into a single string column +} +\examples{ +df = pl$DataFrame( + a = c(1, 2, 3), + b = c("dogs", "cats", NA), + c = c("play", "swim", "walk") +) + +df$with_columns( + pl$concat_str( + pl$col("a") * 2, + "b", + "c", + pl$lit("!"), + separator = " " + )$alias("full_sentence") +) + +} diff --git a/man/pl_max.Rd b/man/pl_max.Rd index 4034c8d09..f3b757be1 100644 --- a/man/pl_max.Rd +++ b/man/pl_max.Rd @@ -28,7 +28,7 @@ df = pl$DataFrame( c = c(1:3, NA_real_) ) # use coalesce to get first non Null value for each row, otherwise insert 99.9 -df$with_column( +df$with_columns( pl$coalesce("a", "b", "c", 99.9)$alias("d") ) diff --git a/man/pl_min.Rd b/man/pl_min.Rd index d3159ac51..34b8b985a 100644 --- a/man/pl_min.Rd +++ b/man/pl_min.Rd @@ -29,7 +29,7 @@ df = pl$DataFrame( d = c(1:2, NA_real_, -Inf) ) # use min to get first non Null value for each row, otherwise insert 99.9 -df$with_column( +df$with_columns( pl$min("a", "b", "c", 99.9)$alias("d") ) diff --git a/man/pl_pl.Rd b/man/pl_pl.Rd index 51c8a7b0b..7672f1663 100644 --- a/man/pl_pl.Rd +++ b/man/pl_pl.Rd @@ -6,7 +6,7 @@ \alias{pl} \title{The complete polars public API.} \format{ -An object of class \code{pl_polars_env} (inherits from \code{environment}) of length 77. +An object of class \code{pl_polars_env} (inherits from \code{environment}) of length 78. } \usage{ pl diff --git a/man/pl_sum.Rd b/man/pl_sum.Rd index 631e23ea0..41e2249ff 100644 --- a/man/pl_sum.Rd +++ b/man/pl_sum.Rd @@ -35,11 +35,11 @@ pl$DataFrame()$select(pl$sum(1:5)) df = pl$DataFrame(a = 1:2, b = 3:4, c = 5:6) # column as list -df$with_column(pl$sum(list("a", "c"))) -df$with_column(pl$sum(list("a", "c", 42L))) +df$with_columns(pl$sum(list("a", "c"))) +df$with_columns(pl$sum(list("a", "c", 42L))) # two eqivalent lines -df$with_column(pl$sum(list(pl$col("a") + pl$col("b"), "c"))) -df$with_column(pl$sum(list("*"))) +df$with_columns(pl$sum(list(pl$col("a") + pl$col("b"), "c"))) +df$with_columns(pl$sum(list("*"))) } \keyword{Expr_new} diff --git a/src/rust/src/lazy/dataframe.rs b/src/rust/src/lazy/dataframe.rs index ea875b77e..b17dd3d6f 100644 --- a/src/rust/src/lazy/dataframe.rs +++ b/src/rust/src/lazy/dataframe.rs @@ -231,6 +231,8 @@ impl LazyFrame { } fn with_column(&self, expr: &Expr) -> LazyFrame { + R!("warning('`with_column()` is deprecated and will be removed in polars 0.9.0. Please use `with_columns()` instead.')") + .expect("warning will not fail"); LazyFrame(self.0.clone().with_column(expr.0.clone())) } diff --git a/src/rust/src/rlib.rs b/src/rust/src/rlib.rs index 5a38dd2f1..f999de008 100644 --- a/src/rust/src/rlib.rs +++ b/src/rust/src/rlib.rs @@ -59,33 +59,40 @@ pub fn hor_concat_df(dfs: &VecDataFrame) -> List { #[extendr] fn min_exprs(exprs: &ProtoExprArray) -> Expr { let exprs = exprs.to_vec("select"); - polars::lazy::dsl::min_exprs(exprs).into() + pl::min_exprs(exprs).into() } #[extendr] fn max_exprs(exprs: &ProtoExprArray) -> Expr { let exprs = exprs.to_vec("select"); - polars::lazy::dsl::max_exprs(exprs).into() + pl::max_exprs(exprs).into() } #[extendr] fn coalesce_exprs(exprs: &ProtoExprArray) -> Expr { let exprs: Vec = exprs.to_vec("select"); - polars::lazy::dsl::coalesce(exprs.as_slice()).into() + pl::coalesce(exprs.as_slice()).into() } #[extendr] fn sum_exprs(exprs: &ProtoExprArray) -> Expr { let exprs = exprs.to_vec("select"); - polars::lazy::dsl::sum_exprs(exprs).into() + pl::sum_exprs(exprs).into() } #[extendr] fn concat_list(exprs: &ProtoExprArray) -> Result { let exprs = exprs.to_vec("select"); - Ok(Expr( - polars::lazy::dsl::concat_list(exprs).map_err(|err| err.to_string())?, - )) + Ok(Expr(pl::concat_list(exprs).map_err(|err| err.to_string())?)) +} + +#[extendr] +fn concat_str(dotdotdot: Robj, separator: Robj) -> RResult { + Ok(pl::concat_str( + robj_to!(Vec, PLExprCol, dotdotdot)?, + robj_to!(str, separator)?, + ) + .into()) } #[extendr] @@ -149,10 +156,7 @@ fn r_date_range_lazy( //for now just use inner directly #[extendr] fn as_struct(exprs: Robj) -> Result { - Ok(polars::lazy::dsl::as_struct( - crate::utils::list_expr_to_vec_pl_expr(exprs, true)?.as_slice(), - ) - .into()) + Ok(pl::as_struct(crate::utils::list_expr_to_vec_pl_expr(exprs, true)?.as_slice()).into()) } #[extendr] @@ -277,6 +281,7 @@ extendr_module! { fn sum_exprs; fn concat_list; + fn concat_str; fn r_date_range; fn r_date_range_lazy; fn as_struct; diff --git a/src/rust/src/rpolarserr.rs b/src/rust/src/rpolarserr.rs index 9cb87673f..a912f148f 100644 --- a/src/rust/src/rpolarserr.rs +++ b/src/rust/src/rpolarserr.rs @@ -8,7 +8,7 @@ use thiserror::Error; #[derive(Clone, Debug, Error)] pub enum Rctx { - #[error("The argument [{0}] cause an error")] + #[error("The argument [{0}] caused an error")] BadArg(String), #[error("Got value [{0}]")] BadVal(String), diff --git a/src/rust/src/utils/mod.rs b/src/rust/src/utils/mod.rs index 47b4558ad..4546602ac 100644 --- a/src/rust/src/utils/mod.rs +++ b/src/rust/src/utils/mod.rs @@ -793,7 +793,11 @@ macro_rules! robj_to { if ($a.is_null()) { Ok(None) } else { - Some($crate::robj_to_inner!($type, $a).bad_arg(stringify!($a))).transpose() + Some( + $crate::robj_to_inner!($type, $a) + .bad_arg(stringify!($a).replace("dotdotdot", " `...` ")), + ) + .transpose() } }) }}; @@ -807,7 +811,7 @@ macro_rules! robj_to { let x = if !x.is_list() && x.len() != 1 { extendr_api::call!("as.list", x) .mistyped(std::any::type_name::()) - .bad_arg(stringify!($a))? + .bad_arg(stringify!($a).replace("dotdotdot", " `...` "))? } else { x }; @@ -835,19 +839,19 @@ macro_rules! robj_to { use $crate::rpolarserr::WithRctx; $crate::robj_to_inner!($type, $a) .and_then($f) - .bad_arg(stringify!($a)) + .bad_arg(stringify!($a).replace("dotdotdot", " `...` ")) }}; ($type:ident, $a:ident) => {{ use $crate::rpolarserr::WithRctx; - $crate::robj_to_inner!($type, $a).bad_arg(stringify!($a)) + $crate::robj_to_inner!($type, $a).bad_arg(stringify!($a).replace("dotdotdot", " `...` ")) }}; ($type:ident, $a:ident, $b:expr) => {{ use $crate::rpolarserr::WithRctx; $crate::robj_to_inner!($type, $a) .hint($b) - .bad_arg(stringify!($a)) + .bad_arg(stringify!($a).replace("dotdotdot", " `...` ")) }}; } diff --git a/tests/testthat/test-expr.R b/tests/testthat/test-expr.R index eaac6d8cb..2d0496767 100644 --- a/tests/testthat/test-expr.R +++ b/tests/testthat/test-expr.R @@ -2344,3 +2344,33 @@ test_that("implode", { expect_identical(pl$lit(1:4)$implode()$to_r(), pl$lit(list(1:4))$to_r()) expect_grepl_error(pl$lit(42)$implode(42), c("unused argument")) }) + +test_that("concat_str", { + df = pl$DataFrame( + a = c(1, 2, 3), + b = c("dogs", "cats", NA), + c = c("play", "swim", "walk") + ) + + out = df$with_columns( + pl$concat_str( + pl$col("a") * 2, + "b", + pl$col("c"), + separator = " " + )$alias("full_sentence") + )$to_data_frame() + + expect_equal(dim(out), c(3, 4)) + expect_equal( + out$full_sentence, + c("2.0 dogs play", "4.0 cats swim", NA) + ) + + # check error for something which cannot be turned into an Expression + ctxs = pl$concat_str("a", complex(1)) |> + (\(x) result(x)$err$contexts())() + expect_identical(ctxs$BadArgument, " `...` ") + expect_identical(ctxs$Hint, "element no. [2] ") + expect_identical(ctxs$PlainErrorMessage, "cannot be converted into an Expr") +}) diff --git a/tests/testthat/test-extendr-meta.R b/tests/testthat/test-extendr-meta.R index 92922542a..9a9708967 100644 --- a/tests/testthat/test-extendr-meta.R +++ b/tests/testthat/test-extendr-meta.R @@ -1,18 +1,16 @@ test_that("clone_robj + mem_adress", { - # clone mutable - env = new.env(parent = emptyenv()) + env = new.env(parent = emptyenv()) env2 = clone_robj(env) env$foo = 42 - expect_identical(env,env2) + expect_identical(env, env2) expect_identical(pl$mem_address(env), pl$mem_address(env2)) # clone immutable, not the same l = list() l2 = clone_robj(l) l$foo = 42 - expect_identical(l,list(foo = 42)) - expect_identical(l2,list()) + expect_identical(l, list(foo = 42)) + expect_identical(l2, list()) expect_false(pl$mem_address(l) == pl$mem_address(l2)) - })