dankelley / oce

R package for oceanographic processing
http://dankelley.github.io/oce/
GNU General Public License v3.0
142 stars 42 forks source link

as.netcdf() etc 'renamer' argument ill-named #2239

Open dankelley opened 2 weeks ago

dankelley commented 2 weeks ago

After discussions with @clayton33 yesterday, I think this should be called nameDict, because I think there should also be an argument called unitDict. (Maybe Dictionary instead of Dict, but that would be a lot of typing for folks who don't use a code-intelligent editor. Also, the word dict is used a lot in computing languages, so I think it will be obvious to all.)

After discussions with @richardsc yesterday, I think these parameters should take either a function (as presently envisioned) or some other things. One thing might be a single character value that would name a yaml file. Another might be a list. Or maybe just start with a list, because a person could do

read.netcdf(file.nc,  yaml::read_yaml("nameDict.yml"))

etc.

Json files might be another choice.

In any case, we have a CRAN release that is very recent, so I won't worry too much about trying tests in the "develop" branch. Of course, I won't push anything to GH until is is clearly documented, and built (likely with a test ... a local test, though, so developers can do it, but there's insufficient justification to add a netcdf file to the package, making it less suitable for CRAN).

dankelley commented 2 weeks ago

Here's an example of the yaml way. I think this wouild be easier for users than writing R code. (Obviously, most of what you see is just me creating the content that would be in a file, so I can do a reprex::reprex() action.)

I need to know more abour NERC/BODC names to proceed much further on this, because I suspect that a grep ignoring a final 2 digits might be needed.

yml <- r"{
info:
  comment: Perhaps the 'renamer' parameter of read.netcdf() should
    accept the name of a yaml file to set things up. The present file
    is a test of the concept.
  date: "2022-08-28"
  name: idea_for_renamer_parameter
  version: 1
units:
  degree_Celsius:
    degree * C
  degrees Celsius:
    degree * C
  micromole/kg:
    mu * mol/kg
variables:
  CNDC:
    conductivity
  PSAL:
    salinity
  TEMP:
    temperature
}"
y <- yaml::read_yaml(text = yml)
y$variables[["TEMP"]]
#> [1] "temperature"
y$units[["degree_Celsius"]]
#> [1] "degree * C"
y$units[["degrees Celsius"]]
#> [1] "degree * C"

Created on 2024-08-29 with reprex v2.1.1

dankelley commented 2 weeks ago

Here's how the above could be done programmatically.

# demonstrate list method
l <- list(
    units = list(
        "degree_Celsius" = "degree * C",
        "degrees Celsius" = "degree * C"
    )
)
l$units[["degree_Celsius"]]
#> [1] "degree * C"
l$units[["degrees Celsius"]]
#> [1] "degree * C"

Created on 2024-08-29 with reprex v2.1.1

dankelley commented 2 weeks ago

I started a branch called "dict", in which any fiddling will be done. That will let me do a bit at a time, without risking problems that will take me from other things.