I'm looking to do string interpolation with R's glue::glue()
on a vector, without calling it multiple times.
Example:
df <- data.frame(x = 1:10)
glue::glue("No. of Rows: {dim(df)[1]}, No. of Columns: {dim(df)[2]}")
Would give as required:
No. of Rows: 10, No. of Columns: 1
But I'm calling dim(df)
twice, where it is a vector of length 2.
I was wondering if glue
can handle this similar to string interpolation in Python with the % operator:
import pandas as pd
df = pd.DataFrame({"x": range(10)})
print('No. of Rows: %d, No. of Columns: %d' % df.shape)
Which gives the same required output without calling df.shape
twice.