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

Adjust for glue 1.8.0 compatibility #162

Merged
merged 2 commits into from
Dec 9, 2024
Merged

Adjust for glue 1.8.0 compatibility #162

merged 2 commits into from
Dec 9, 2024

Conversation

kyleam
Copy link
Contributor

@kyleam kyleam commented Nov 19, 2024

This PR updates yspec to be compatible with glue 1.8.0, which no longer accepts a list for its .envir argument.

As described in the second commit message, this PR introduces a change in the lookup behavior, eliminating a case where the value could come from the global environment. (In my view, it's acceptable and can be considered a fix.)

Related PRs:

Minimize the number of spots that will need to be adjusted for
compatibility with glue 1.8.0.
As of v1.8.0, glue::glue aborts if its .envir argument is not an
environment.  yspec passes a list in two spots.  To make these
compatible with v1.8.0, we could 1) convert the list argument to an
environment before passing it to as .envir or 2) call glue_data and
pass the list to its .x argument.  Both those options can express the
same evaluation environments.

In either case, there is a change in behavior here.  With glue
versions before 1.8.0, passing a list to .envir leads to an eval
environment that is undocumented (and likely surprising to the
caller): eval uses the glue:::identity_transformer environment as the
enclosing environment.  The main user-visible consequence is that, if
an item isn't found in the specified list, it can be grabbed from the
global environment.

In the context of yspec, that isn't behavior that should be supported.
The values should be defined by the list coming from the spec.

Convert the incompatible calls to glue_data calls that pass the list
as .x and specify an empty environment.
@@ -18,7 +18,7 @@ x_table_2_details <- function(x) {
x_table_2_table_row <- function(x,details_fun) {
unit <- NULL
if(.has("unit",x)) {
unit <- glue::glue(" ({unit})", .envir = x)
unit <- glue::glue_data(x, " ({unit})", .envir = emptyenv())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this call isn't covered by the test suite, but I checked it manually with the changes below.

diff
diff --git a/check-xtable.R b/check-xtable.R
new file mode 100644
index 0000000..8b1f119
--- /dev/null
+++ b/check-xtable.R
@@ -0,0 +1,2 @@
+devtools::load_all()
+render_define("inst/spec/project.yml")
diff --git a/inst/spec/DEM104101F_AE.yml b/inst/spec/DEM104101F_AE.yml
index 21ba705..3f7b534 100644
--- a/inst/spec/DEM104101F_AE.yml
+++ b/inst/spec/DEM104101F_AE.yml
@@ -2,6 +2,8 @@ SETUP__:
   description: AE analysis data set
   sponsor: Some other company
   data_stem: DEM0104101F_AE_2
+  glue:
+    foo: bar
 C:
   long: commented rows
   values: [".",C]
@@ -26,7 +28,7 @@ CMT:
   comment: per NONMEM specifications
   values: [1,2,3,4]
 TAFD:
-  unit: hours
+  unit: <<foo>>
   long: time after first dose
 WT:
   about: [Weight, kg]
diff --git a/inst/spec/project.yml b/inst/spec/project.yml
index a181527..7dc4e71 100644
--- a/inst/spec/project.yml
+++ b/inst/spec/project.yml
@@ -2,16 +2,16 @@
 YPROJ__:
   sponsor: ABC-Pharma
   projectnumber: ABC101104F
-  yml_file: /Users/kyleb/ghe/software/yspec/inst/spec/project.yml
-  proj_file: /Users/kyleb/ghe/software/yspec/inst/spec/project.yml
-  proj_path: /Users/kyleb/ghe/software/yspec/inst/spec
-  path: /Users/kyleb/ghe/software/yspec/inst/spec
+  yml_file: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec/project.yml
+  proj_file: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec/project.yml
+  proj_path: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec
+  path: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec
   class: yproj
 DEM104101F_PK:
   name: DEM104101F_PK
   description: Population PK analysis data set
-  spec_path: /Users/kyleb/ghe/software/yspec/inst/spec
-  spec_file: /Users/kyleb/ghe/software/yspec/inst/spec/DEM104101F_PK.yml
+  spec_path: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec
+  spec_file: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec/DEM104101F_PK.yml
   data_path: ../data/derived
   data_stem: DEM104101F_PK
   csv_file: ../data/derived/DEM104101F_PK.csv
@@ -19,8 +19,8 @@ DEM104101F_PK:
 DEM104101F_PKPD:
   name: DEM104101F_PKPD
   description: Population PKPD analysis data set
-  spec_path: /Users/kyleb/ghe/software/yspec/inst/spec
-  spec_file: /Users/kyleb/ghe/software/yspec/inst/spec/DEM104101F_PKPD.yml
+  spec_path: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec
+  spec_file: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec/DEM104101F_PKPD.yml
   data_path: ../data/derived
   data_stem: DEM104101F_PKPD
   csv_file: ../data/derived/DEM104101F_PKPD.csv
@@ -28,8 +28,8 @@ DEM104101F_PKPD:
 DEM104101F_AE:
   name: DEM104101F_AE
   description: AE analysis data set
-  spec_path: /Users/kyleb/ghe/software/yspec/inst/spec
-  spec_file: /Users/kyleb/ghe/software/yspec/inst/spec/DEM104101F_AE.yml
+  spec_path: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec
+  spec_file: /data/home/kylem/src/github/metrumresearchgroup/yspec/inst/spec/DEM104101F_AE.yml
   data_path: ../data/derived
   data_stem: DEM0104101F_AE_2
   csv_file: ../data/derived/DEM0104101F_AE_2.csv

@kyleam kyleam requested a review from kylebaron November 19, 2024 18:23
@kyleam kyleam merged commit 099177a into main Dec 9, 2024
5 checks passed
@kyleam kyleam deleted the glue-compat branch December 9, 2024 12:58
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