poissonconsulting / subfoldr2

An R package to facilitate saving and loading objects, data, plots, numbers and strings
https://poissonconsulting.github.io/subfoldr2/
Other
2 stars 0 forks source link

`sbf_save_number()` csv format save the column name as x_name #98

Closed aylapear closed 1 year ago

aylapear commented 1 year ago

I assume that when sbf_save_number() creates the csv file it should create a column name based on the variable passed or the x_name argument.

x <- 1L
sbf_save_number(x, "var_name")

Screenshot 2023-06-26 at 11 43 00 AM

It creates the column name as x_name even if an x_name is passed.

The rds file it creates is done correctly.

joethorley commented 1 year ago

Makes sense - unless file names can include characters that are not permitted in column names? If so I think we could drop the column name entirely

aylapear commented 1 year ago

Do we want the file name to come from the x_name (if supplied) and the column name to always come the x argument?

I don't think that file names and column names have to the same rules on what they can be named. If we go with the x argument then the column names would be restricted to only the rules for naming variables in R.

joethorley commented 1 year ago

On reflection I think the column name could always just be x as its not really adding any information beyond the file name. Ideally we wouldn't have any column name at all as the purpose is just to store a scalar value.

joethorley commented 1 year ago

I when I say x I mean the literal x as opposed to the name of variable x.

aylapear commented 1 year ago

Just to clarify I understand what you mean here are two examples.

Example 1 (x_name supplied):

y <- 1L
sbf_save_number(y, x_name = "var_name")

Then the file would be var_name.csv and var_name.rds and inside the csv we would have

x
1

Example 2 (no x_name):

y <- 1L
sbf_save_number(y)

Then the file would be y.csv and y.rds and inside the csv we would have

x
1
joethorley commented 1 year ago

Yes exactly that!

aylapear commented 1 year ago

Updated the pull request to this change