I had a little question regarding blogdown::write_toml. The thing is I am not quite sure how to deal with datetime objects when writing the toml file after I edit it. If I keep date time in native format (as.Posixct), then write_toml converts the date time to some float number (e.g. 2021-01-02 00:05:00 becomes 1546387200.0. I guess time after some origin timestep). If I convert datetime to character, single quotes occur around the datetime (e.g. 2021-01-02 00:05:00 becomes '2021-01-02 00:05:00'). What is the right way to keep the datetime in R object, so that write_toml would result in: start_date = 2021-01-02 00:05:00 ? (without quotes)
Converting to YAML the R object using as.yaml(x) and writing to a file
Running Hugo to convert to toml using hugo convert to TOML
I believe when converting to file format, if you want to keep some date format as string, you need to already convert it in the desired format from the start.
Hello Christophe,
Thank you for your reply. This as.yaml command indeed helps to recognize the R datetime format, however the resulting toml file contains the datetime in the format "2023-01-09 09:51:01 +0100\n" while I need 2023-01-09 09:51:01 (without quotes and +0100\n). Is there a way to manage that?
Thanks in advance,
Alex
Hello Christophe,
Thanks again for your attention to this topic. I guess essentially what I would like to know is how to avoid the quotes in the final output, e.g. getting 2023-01-09 09:51:01 instead of '2023-01-09 09:51:01' in the generated toml file.
Thanks in advance,
Alex
Oh i understand now. Probably because it is seen as string and then quoted
So maybe it should be done this way, and there is a way to format date ?
As I said conversion happens with Hugo after writing YAML. So probably need to look in TOML type and how to get a date formatted. I don't know enough so I would need to try out different things - which you could do.
YAML conversion also can lose some date format.
At the bottom hugo convert is used (hugo convert toTOML | Hugo) I don't know if any other tools allow to convert to TOML.