| Title: | Automatically Fetching References Metadata from Literature Databases |
|---|---|
| Description: | Provides functions to automatically retrieve and deduplicate reference metadata based on saved search strings. Access to Web of Science and Scopus requires personal API keys, while PubMed can be queried without one. The optional deduplication functionality requires the package 'ASySD' available from <https://github.com/camaradesuk/ASySD>. |
| Authors: | Thomas Dumond [cre, aut, cph] (ORCID: <https://orcid.org/0000-0002-9427-8649>), Charles Caraguel [ctb] (ORCID: <https://orcid.org/0000-0003-0019-4813>), Torben Nielsen [ctb] (ORCID: <https://orcid.org/0000-0002-8941-7376>) |
| Maintainer: | Thomas Dumond <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.0 |
| Built: | 2026-11-13 00:00:59 UTC |
| Source: | https://github.com/thomasdumond/litfetchr |
Creates a read-only Rscript and a task to run the code automatically at a specified frequency and time, to retrieve references corresponding to the saved search string(s) on up to three platforms (e.g. Web of Science, Scopus and PubMed).
auto_LitFetchR_setup( task_id = "task_id", when = "DAILY", time = "08:00", wos = FALSE, scp = FALSE, pmd = FALSE, directory, dedup = FALSE, open_file = FALSE, dry_run = FALSE, day = NULL, output_format = c("csv", "ris") )auto_LitFetchR_setup( task_id = "task_id", when = "DAILY", time = "08:00", wos = FALSE, scp = FALSE, pmd = FALSE, directory, dedup = FALSE, open_file = FALSE, dry_run = FALSE, day = NULL, output_format = c("csv", "ris") )
task_id |
Name of the automated reference retrieval task
(e.g. one keyword describing your review). Spaces are replaced by "-".
A task with the same name must not exist already: use
|
when |
Frequency of the automated reference retrieval task (DAILY, WEEKLY or MONTHLY). |
time |
Time of the automated reference retrieval task (must be HH:MM 24-hour clock format). |
wos |
Runs the search on Web of Science (TRUE or FALSE). |
scp |
Runs the search on Scopus (TRUE or FALSE). |
pmd |
Runs the search on PubMed (TRUE or FALSE). |
directory |
Choose the directory in which the search string is saved (Project's directory). That is also where the references metadata will be saved. |
dedup |
Deduplicates the retrieved references (TRUE or FALSE). |
open_file |
Automatically opens the output file after reference retrieval. |
dry_run |
Simulation run option. |
day |
Day on which a WEEKLY or MONTHLY task runs. For WEEKLY, one of
MON, TUE, WED, THU, FRI, SAT or SUN. For MONTHLY, a day of the month
between 1 and 28. If |
output_format |
Format of the file of references written at each run:
|
The function reports "Task scheduled!" only after checking that the scheduler accepted the task and that the task exists. On Windows the registered task is read back from Task Scheduler and compared with the requested schedule. A short summary (recurrence, next run time and status) is then printed. If the scheduler returns an error, the function stops and shows the scheduler's own message. If the task cannot be confirmed, a warning is given instead of the success message. Check the summary: it is the only evidence that automatic retrieval will run.
The scheduled task runs only while the computer is on and you are logged in.
Each run is recorded in run_log.csv (see manual_fetch()) with the name
of the task in the column run_mode. When a run fails, or finishes with
problems on one platform, it ends with a non-zero exit status, which the
Windows Task Scheduler shows as the Last Run Result of the task.
NULL (invisibly). Called for its side effects:
writes an R script and schedules a task (Windows Task Scheduler or cron)
to run the script automatically. The function stops with the scheduler's
error message if the task cannot be created, and gives a warning if the
new task cannot be confirmed.
# This is a "dry run" example. # No task will actually be scheduled, # it only shows how the function should react. auto_LitFetchR_setup(task_id = "fish_vibrio", when = "WEEKLY", time = "14:00", day = "MON", wos = TRUE, scp = TRUE, pmd = TRUE, directory, dedup = FALSE, open_file = FALSE, dry_run = TRUE )# This is a "dry run" example. # No task will actually be scheduled, # it only shows how the function should react. auto_LitFetchR_setup(task_id = "fish_vibrio", when = "WEEKLY", time = "14:00", day = "MON", wos = TRUE, scp = TRUE, pmd = TRUE, directory, dedup = FALSE, open_file = FALSE, dry_run = TRUE )
An interactive function that ask the user to enter a search string and provide the number of results from 3 platforms: Web of Science, Scopus and PubMed. You can then save one or more search strings to retrieve the references later.
create_save_search( wos = FALSE, scp = FALSE, pmd = FALSE, directory, dry_run = FALSE )create_save_search( wos = FALSE, scp = FALSE, pmd = FALSE, directory, dry_run = FALSE )
wos |
Runs the search on Web of Science (TRUE or FALSE). |
scp |
Runs the search on Scopus (TRUE or FALSE). |
pmd |
Runs the search on PubMed (TRUE or FALSE). |
directory |
Choose the directory in which the search string and the search history will be saved. |
dry_run |
Simulation run option. |
Type summary to display the searches run so far and save one of them
(the saved search strings are stored in "search_list.txt", which is
required by the retrieval functions). Type exit to leave the tool. If
searches were run but none was saved during the session, exit first
offers to save one.
NULL (invisibly). Called for its side effects:
interactive querying and writing search history files.
# This is a "dry run" example. # No search will be created and no database will be accessed. # It only shows how the function should react. create_save_search(wos = TRUE, scp = TRUE, pmd = TRUE, directory, dry_run = TRUE)# This is a "dry run" example. # No search will be created and no database will be accessed. # It only shows how the function should react. create_save_search(wos = TRUE, scp = TRUE, pmd = TRUE, directory, dry_run = TRUE)
Deduplicates the references from up to three dataframes.
dedup_refs( df1 = NULL, df2 = NULL, df3 = NULL, directory, open_file = FALSE, dry_run = FALSE, output_format = c("csv", "ris") )dedup_refs( df1 = NULL, df2 = NULL, df3 = NULL, directory, open_file = FALSE, dry_run = FALSE, output_format = c("csv", "ris") )
df1 |
Dataframe 1 (can be NULL) |
df2 |
Dataframe 2 (can be NULL) |
df3 |
Dataframe 3 (can be NULL) |
directory |
Choose the directory in which the references deduplication history will be saved. |
open_file |
Automatically opens the output file after reference retrieval. |
dry_run |
Simulation run option. |
output_format |
Format of the file of deduplicated references: |
NULL (invisibly). Called for its side effects:
writes a CSV or RIS file of deduplicated citations and
an Excel workbook recording the deduplication history.
# This is a "dry run" example. # No deduplication will happen. # It only shows how the function should react. dedup_refs(df1 = df_vibrio_wos, df2 = df_vibrio_scp, df3 = df_vibrio_pmd, directory = tempdir(), open_file = FALSE, dry_run = TRUE )# This is a "dry run" example. # No deduplication will happen. # It only shows how the function should react. dedup_refs(df1 = df_vibrio_wos, df2 = df_vibrio_scp, df3 = df_vibrio_pmd, directory = tempdir(), open_file = FALSE, dry_run = TRUE )
Retrieves references corresponding to the saved search string(s) on up to three platforms (e.g. Web of Science, Scopus and PubMed).
manual_fetch( wos = FALSE, scp = FALSE, pmd = FALSE, directory, dedup = FALSE, open_file = FALSE, dry_run = FALSE, output_format = c("csv", "ris") )manual_fetch( wos = FALSE, scp = FALSE, pmd = FALSE, directory, dedup = FALSE, open_file = FALSE, dry_run = FALSE, output_format = c("csv", "ris") )
wos |
Runs the search on Web of Science (TRUE or FALSE). |
scp |
Runs the search on Scopus (TRUE or FALSE). |
pmd |
Runs the search on PubMed (TRUE or FALSE). |
directory |
Choose the directory in which the search string is saved (Project's directory). That is also where the references metadata will be saved. |
dedup |
Deduplicates the retrieved references (TRUE or FALSE). |
open_file |
Automatically opens the output file after reference retrieval. |
dry_run |
Simulation run option. |
output_format |
Format of the file of references: |
Every retrieval is recorded in the file run_log.csv of directory
(one row per saved search and platform, or one row with platform "all" if
the run could not start, for example because search_list.txt is invalid).
It records whether the run was started by hand or by a scheduled task
(run_mode). It stores the exact query
submitted to each platform, the date, the package and R versions, the
number of results and new records, the status of the request and any
error message. For PubMed, it also stores the query translation reported
by PubMed. For Web of Science, it also stores the number of records
retrieved from each source database.
The history of the references already retrieved (history_id.xlsx) is
only updated once the output file has been written. If a platform fails
(for example an expired API key), the other platforms are still saved,
a warning names the failed platform(s), and the failed platform is not
added to the history, so its references are retrieved again by the next
run. If all the selected platforms fail, an error is raised.
When there is no new record, no output file is written.
NULL (invisibly). Called for its side effects: Create a CSV or RIS file with the references metadata, a history file of the references retrieved, a history file of the deduplication (if the option is selected) and a run log (run_log.csv).
# This is a "dry run" example. # No references will actually be scheduled, it only shows how the function should react. manual_fetch(wos = TRUE, scp = TRUE, pmd = TRUE, directory, dedup = TRUE, open_file = FALSE, dry_run = TRUE )# This is a "dry run" example. # No references will actually be scheduled, it only shows how the function should react. manual_fetch(wos = TRUE, scp = TRUE, pmd = TRUE, directory, dedup = TRUE, open_file = FALSE, dry_run = TRUE )
Removes a scheduled task using the "task_id" from Task Scheduler (Windows) or Cron (Mac/Linux).
remove_scheduled_task(task_id, dry_run = FALSE)remove_scheduled_task(task_id, dry_run = FALSE)
task_id |
Name/ID of the scheduled task (Windows Task Scheduler or Cron). |
dry_run |
Simulation run option. |
The function checks whether the task exists first, removes it, then checks that it is gone. It reports which of these happened. If the task does not exist, nothing is removed and a message says so. If the scheduler returns an error, or the task is still there afterwards, the function stops and shows the scheduler's own message.
NULL (invisibly). Called for its side effects: removes a scheduled task saved using the function 'auto_LitFetchR_setup'.
# This is a "dry run" example. # No task will actually be removed, it only shows how the function should react. remove_scheduled_task("fish_vibrio", dry_run = TRUE )# This is a "dry run" example. # No task will actually be removed, it only shows how the function should react. remove_scheduled_task("fish_vibrio", dry_run = TRUE )
You can set wos_api_key, scp_api_key, scp_insttoken, ncbi_api_key, or any combination. Remember to restart the R session after saving your API keys.
save_api_keys( wos_api_key = NULL, scp_api_key = NULL, scp_insttoken = NULL, ncbi_api_key = NULL, dry_run = FALSE )save_api_keys( wos_api_key = NULL, scp_api_key = NULL, scp_insttoken = NULL, ncbi_api_key = NULL, dry_run = FALSE )
wos_api_key |
The API key value for Web of Science (use quotation marks). |
scp_api_key |
The API key value for Scopus (use quotation marks). |
scp_insttoken |
The institutional token for Scopus (use quotation marks). Required by some institutional Scopus subscriptions alongside the API key. |
ncbi_api_key |
The API key value for NCBI/PubMed (use quotation marks). Optional; when set, PubMed requests run at a higher rate limit. |
dry_run |
Simulation run option. |
Logical. TRUE if at least one value was written, FALSE if left unchanged.
save_api_keys(wos_api_key = "abcd01234", scp_api_key = "efgh5678", dry_run = TRUE )save_api_keys(wos_api_key = "abcd01234", scp_api_key = "efgh5678", dry_run = TRUE )