crsh / citr

RStudio Addin to Insert Markdown Citations
Other
407 stars 46 forks source link

Allow for different types of citation key formats in tidy_bib_file() #81

Open ilsePit opened 3 years ago

ilsePit commented 3 years ago

This request is with regards the regular expression used in line 48 in tidy_bib_file.R.

The current regex used does not account for the format of citation keys I use (Author-et-al_2020), and I can imagine this is true for others as well. I notice the commented-out regex in line 47 and 49 would do the trick as I need them to. What was the reason these were disregarded? I have to admit I am not fluent enough in regex to figure it out so far.

I suggest adding a regex parameter to tidy_bib_file(), in which the used can specify the regex they want to use to read their citation keys (with a default given).

I'd happily make a pull request but wanted to make sure to check why the regex in line 48 was chosen first.

Thanks!

ilsePit commented 3 years ago

suggested regex as default: "@[^(.|;|,|?|!)\s\]\)]+" , adjusted from line 47.

crsh commented 3 years ago

Hi, thanks for the feedback. I'm all for supporting your citation key format and I think allowing users to specify custom regex is a great idea! I added the regex in question in response to this issue: https://github.com/crsh/citr/issues/49 Regrettably, it seems I did not implement the problematic keys as unit tests. So as a strategy for a PR, I think it would be great to first create a Rmd file containing a range of different test cases and then adjusting the regex to ensure it catches all cases. This would inform us, about whether the regex you suggest preserves the current functionality and adds the desired flexibility.

ilsePit commented 3 years ago

Not sure I know exactly what you mean, I'm quite new to sharing code, so forgive me for asking rudimentary questions :). i understand making an Rmd and bib with a ton of different keys would be helpful in figuring out the best regex, but would you want me to push these to this repository? Or is there another way to do this (collaboratively) without adding those files to this repo? I can also do the test locally and then push once I find the Ultimate Regex (if that exists). Thanks!