Al-Murphy / MungeSumstats

Rapid standardisation and quality control of GWAS or QTL summary statistics
https://doi.org/doi:10.18129/B9.bioc.MungeSumstats
75 stars 16 forks source link

Avoid appending old log files #80

Open bschilder opened 2 years ago

bschilder commented 2 years ago

Reprex

 gwas_paths <- MungeSumstats::import_sumstats(ids = meta$id, 
                                       save_dir = save_dir, 
                                       nThread = 50, 
                                       parallel_across_ids = TRUE,
                                       force_new_vcf = TRUE,
                                       force_new = TRUE,
                                       #### Record logs
                                       log_folder_ind = TRUE,
                                       log_mungesumstats_msgs = TRUE)

Issue: part 1

If you run format_sumstats with the log file options set, but then try to later re-munge some of those files, the log files from the previous runs get appended with the output from the new runs.

Here, you can see where it finished the old run and started the new run right around the middle ("Importing VCF file: ..."):

Screenshot 2021-12-23 at 14 12 33

Issue: part 2

Also, I noticed that If I start the above code, but then stop it midway, do some stuff in the R console , and then run it again, it will start recording my output from the console! (not the output of the munging process). This also gets appended to any pre-existing log files.

Screenshot 2021-12-23 at 14 11 26


Session info

```R ```
Al-Murphy commented 2 years ago

I don't know if there is a good way around part 2 issue, this is an annoyance with the sink() function, you have to close connections to the file you are logging results to:

https://stackoverflow.com/questions/18730491/sink-does-not-release-file

bschilder commented 2 years ago

I wonder if closing all connections with this function might work: https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/on.exit

Specifically, i find base::closeAllConnections() to be the most comprehensive

Al-Murphy commented 2 years ago

Yep but you have to do it manually, if you quite MungeSumstats or it fails you have to call that yourself, no way for the function to I don't think

bschilder commented 2 years ago

Ok, I think I see what you mean. so like you have to wrap whatever function with on.exit(), as opposed to putting it within the function itself.

I'll keep looking around and see if there's a solution out there.