Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code in parse_citation.R #221

Merged
merged 15 commits into from Jan 14, 2019
Merged

Clean code in parse_citation.R #221

merged 15 commits into from Jan 14, 2019

Conversation

hsonne
Copy link
Contributor

@hsonne hsonne commented Dec 12, 2018

Just another cleaned file, see commit messages... Thanks for review, Hauke

cboettig and others added 15 commits December 4, 2018 09:13
- put assignment between bibentry and schema into
  new function bibentry_to_schema_field().
- codemeta was only used to get the "author" field,
  so there is no need to save it in a variable.
- Instead, assign "author" (renamed from "authors")
  directly.
- Move comment about bibentry types towards
  bibentry_to_schema_field()
parse_citation()
- Extract determination of type into new function
  bibentry_to_schema_field()
- Extract determination of id (URL of doi.org
  resource) into new function to_url_doi_or_null()
- Split the rest into two main functions:
  init_citation() and parse_journal()
- always paste the result of parse_journal() with
  c() to the initialised citation. As it may be
  NULL, citation may not alter if it does not
  refer to a journal article. No need for an extra
  if().
to_url_doi_or_null()
- Return early if there is no doi or if doi
  already is (better: looks like) a doi.org-URL
- Use new function get_url_doi() to generate the
  URL
- No need for "else" as we always return()
init_citation()
- Already include "@id" and "sameAs" in the
  list(). These entries will be removed by the
  surrounding drop_null() in case that id is NULL.
parse_journal()
- Return NULL if this is not a journal bibentry.
- By doing it here, the upper level code can be
  clearer. The result may be used directly in
  c(x, result) and x will not change if result is
  NULL.
guess_citation()
- Use existing helper function
  installed_package_names(). Create the path to
  CITATION only once and store it in citation_file
- Create intermediate logical variables to improve
  readability
- Return early with NULL if there is neither a
  citation file nor is the package installed
- Encapsulate reading of the citation file into
  new function read_citation_with_encoding()
read_citation_with_encoding()
- Call utils::readCitationFile() only once with
  meta being either NULL or a list with element
  "Encoding".
@maelle maelle requested a review from cboettig December 18, 2018 13:48
@cboettig
Copy link
Member

@maelle this looks good to me (I restarted the stalled travis build as well)

@maelle maelle merged commit 127d52e into ropensci:dev Jan 14, 2019
@hsonne hsonne deleted the clean/citation branch January 14, 2019 16:58
maelle added a commit that referenced this pull request Apr 1, 2020
## Deprecation

* The use_git_hook argument of write_codemeta() has been deprecated. Solutions for keeping DESCRIPTION and codemeta.json in sync are available in the docs.

## Enhancements

* Docs were improved to make a better case for codemetar.

* Changes in the way codeRepository is guessed. codemetar can now recognize an URL from GitHub, GitLab, Bitbucket, R-Forge among several URLs in DESCRIPTION, to assign it to codeRepository. If no URL in DESCRIPTION is from any of these providers, `guess_github()` is called.

* Adds documentation of internet needs and verbosity to steps downloading information from the web (#270, @Bisaloo)

* New argument `write_minimeta` for `write_codemeta()` indicating whether to also create the file schemaorg.json that  corresponds to the metadata Google would validate, to be inserted to a webpage for SEO. It is saved as "schemaorg.json" alongside `path` (by default, "codemeta.json"). This functionality requires the `jsonld` package (listed under `Suggests`).

## Bug fixes

* Fix for detecting rOpenSci review badge (@sckott, #236)

* Fix extraction of ORCID when composite comment (@billy34, #231)

* Fix bug in crosswalking (#243)

* Bug fix: the codeRepository is updated if there's any URL in DESCRIPTION.

* Bug fix: the README information is now updated by codemeta_readme(). Previously if e.g. a developmentStatus had been set previously, it was never updated.

## Internals

* Code cleaning following the book Martin, Robert C. Clean code: a handbook of agile software craftsmanship. Pearson Education, 2009. (@hsonne, #201, #202, #204, #205, #206, #207, #209, #210, #211, #212, #216, #218, #219, #220, #221).

* Use of re-usable Rmd pieces for the README, intro vignette and man pages to reduce copy-pasting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants