Introduction to sched package

sched helps sending SOAP or regular requests to web servers, while respecting a maximum requesting frequency, as stated by web sites for the usage of their web services.

sched uses fscache package to store returned contents of requests, reusing them automatically when the same request is run again.

Requests are sent through the use of an instance of the Scheduler class.

Initializing the scheduler

To get an instance of a scheduler, we use the Scheduler class as following:

scheduler <- sched::Scheduler$new(cache_dir = NULL,
                                  user_agent = "sched ; pierrick.roger@cea.fr")

Be sure to set a user agent, since this is what will identify your application to the web site. Some web site may reject requests because of an empty user agent.

For this vignette we disable the cache folder by setting cache_dir to NULL. By default it is set to sched folder inside the default user cache folder on the system. It is however strongly recommended to set it to a folder named after your application. Example: sched::Scheduler$new(cache_dir=tools::R_user_dir("my.app", which = "cache")).

Sending a request to a web service

To send a request to a web service and retrieve the content of the response, we use the sendRequest() method.

Inside sendRequest(), the scheduler will automatically limit the access frequency to the domain name. This means that the call to sendRequest() may block sometime, doing nothing. This is perfectly normal.

Before sending a request we must build a Request object that we will pass to sendRequest(). Using classes like Request and URL may be cumbersome for basic requests, but is very handy for more complex ones, like POST requests.

Let us a build a URL object and a simple Request object that takes only a URL:

my_url <- sched::URL$new(
  url = "https://www.ebi.ac.uk/webservices/chebi/2.0/test/getCompleteEntity",
  params = c(chebiId = 15440)
)

my_request <- sched::Request$new(my_url)

To send the request, pass the Request object to the sendRequest() method:

content <- scheduler$sendRequest(my_request)

Here is the XML content returned by the ChEBI web service:

content
#> [1] "<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><getCompleteEntityResponse xmlns=\"https://www.ebi.ac.uk/webservices/chebi\"><return><chebiId>CHEBI:15440</chebiId><chebiAsciiName>squalene</chebiAsciiName><definition>A triterpene consisting of 2,6,10,15,19,23-hexamethyltetracosane having six double bonds at the 2-, 6-, 10-, 14-, 18- and 22-positions with (all-E)-configuration.</definition><status>CHECKED</status><smiles>CC(C)=CCC\\C(C)=C\\CC\\C(C)=C\\CC\\C=C(/C)CC\\C=C(/C)CCC=C(C)C</smiles><inchi>InChI=1S/C30H50/c1-25(2)15-11-19-29(7)23-13-21-27(5)17-9-10-18-28(6)22-14-24-30(8)20-12-16-26(3)4/h15-18,23-24H,9-14,19-22H2,1-8H3/b27-17+,28-18+,29-23+,30-24+</inchi><inchiKey>YYGNTYWPHWGJRM-AAJYLUCBSA-N</inchiKey><charge>0</charge><mass>410.730</mass><monoisotopicMass>410.39125</monoisotopicMass><entityStar>3</entityStar><SecondaryChEBIIds>CHEBI:10843</SecondaryChEBIIds><SecondaryChEBIIds>CHEBI:9245</SecondaryChEBIIds><SecondaryChEBIIds>CHEBI:10795</SecondaryChEBIIds><SecondaryChEBIIds>CHEBI:15104</SecondaryChEBIIds><SecondaryChEBIIds>CHEBI:26746</SecondaryChEBIIds><Synonyms><data>(all-E)-2,6,10,15,19,23-hexamethyl-2,6,10,14,18,22-tetracosahexaene</data><type>SYNONYM</type><source>NIST Chemistry WebBook</source></Synonyms><Synonyms><data>Spinacene</data><type>SYNONYM</type><source>KEGG COMPOUND</source></Synonyms><Synonyms><data>Squalene</data><type>SYNONYM</type><source>KEGG COMPOUND</source></Synonyms><Synonyms><data>squalene</data><type>SYNONYM</type><source>UniProt</source></Synonyms><Synonyms><data>Supraene</data><type>SYNONYM</type><source>KEGG COMPOUND</source></Synonyms><IupacNames><data>(6E,10E,14E,18E)-2,6,10,15,19,23-hexamethyltetracosa-2,6,10,14,18,22-hexaene</data><type>IUPAC NAME</type><source>IUPAC</source></IupacNames><Formulae><data>C30H50</data><source>ChEBI</source></Formulae><RegistryNumbers><data>111-02-4</data><type>CAS Registry Number</type><source>KEGG COMPOUND</source></RegistryNumbers><RegistryNumbers><data>111-02-4</data><type>CAS Registry Number</type><source>ChemIDplus</source></RegistryNumbers><RegistryNumbers><data>111-02-4</data><type>CAS Registry Number</type><source>NIST Chemistry WebBook</source></RegistryNumbers><RegistryNumbers><data>1728920</data><type>Beilstein Registry Number</type><source>Beilstein</source></RegistryNumbers><Citations><data>16341241</data><type>PubMed citation</type><source>Europe PMC</source></Citations><Citations><data>23625688</data><type>PubMed citation</type><source>Europe PMC</source></Citations><Citations><data>24362891</data><type>PubMed citation</type><source>Europe PMC</source></Citations><Citations><data>25286851</data><type>PubMed citation</type><source>Europe PMC</source></Citations><Citations><data>25286853</data><type>PubMed citation</type><source>Europe PMC</source></Citations><Citations><data>25987292</data><type>PubMed citation</type><source>Europe PMC</source></Citations><ChemicalStructures><structure>\n  Ketcher 05282116592D 1   1.00000     0.00000     0\n\n 30 29  0     0  0            999 V2000\n    7.0643   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    7.9173   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    8.7704   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    9.6234   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   10.4765   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   11.3295   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   12.1826   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   13.0356   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   13.8887   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   14.7417   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   15.5948   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   16.5135   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   17.3666   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   18.2196   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   19.0727   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   19.9257   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   20.7788   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   21.6318   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   22.4849   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   23.3379   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   24.1909   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   25.0440   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   25.8970   -4.2268    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   26.7502   -4.7517    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    7.9173   -5.7360    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   11.3295   -5.7360    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   14.7417   -5.7360    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   19.0727   -3.2426    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   22.4849   -3.2426    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   25.8970   -3.2426    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  2  1  1  0     0  0\n  3  2  2  0     0  0\n 25  2  1  0     0  0\n  4  3  1  0     0  0\n  5  4  1  0     0  0\n  6  5  1  0     0  0\n  7  6  2  0     0  0\n 26  6  1  0     0  0\n  8  7  1  0     0  0\n  9  8  1  0     0  0\n 10  9  1  0     0  0\n 11 10  2  0     0  0\n 27 10  1  0     0  0\n 12 11  1  0     0  0\n 13 12  1  0     0  0\n 14 13  1  0     0  0\n 15 14  2  0     0  0\n 16 15  1  0     0  0\n 28 15  1  0     0  0\n 17 16  1  0     0  0\n 18 17  1  0     0  0\n 19 18  2  0     0  0\n 20 19  1  0     0  0\n 29 19  1  0     0  0\n 21 20  1  0     0  0\n 22 21  1  0     0  0\n 23 22  2  0     0  0\n 24 23  1  0     0  0\n 30 23  1  0     0  0\nM  END\n</structure><type>mol</type><dimension>2D</dimension><defaultStructure>true</defaultStructure></ChemicalStructures><ChemicalStructures><structure>SQL - Ideal conformer\n  Mrv1927 05282116593D          \n\n 80 79  0  0  0  0            999 V2000\n  -10.3140    1.3190   -1.3860 C   0  0  0  0  0  0  0  0  0  0  0  0\n  -10.9120    0.1620   -0.6270 C   0  0  0  0  0  0  0  0  0  0  0  0\n  -12.3920    0.1310   -0.3440 C   0  0  0  0  0  0  0  0  0  0  0  0\n  -10.1450   -0.8160   -0.2130 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -8.6500   -0.7260   -0.3840 C   0  0  1  0  0  0  0  0  0  0  0  0\n   -7.9680   -0.9340    0.9690 C   0  0  1  0  0  0  0  0  0  0  0  0\n   -6.4740   -0.8440    0.7980 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.6890   -2.0600    0.3780 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.8570    0.2920    1.0130 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.3520    0.3530    0.9630 C   0  0  1  0  0  0  0  0  0  0  0  0\n   -3.9190    1.4360   -0.0270 C   0  0  1  0  0  0  0  0  0  0  0  0\n   -2.4140    1.4980   -0.0780 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.6590    2.3220    0.9330 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.7620    0.8340   -1.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.2550    0.8030   -0.9830 C   0  0  1  0  0  0  0  0  0  0  0  0\n    0.2250   -0.6500   -0.9920 C   0  0  1  0  0  0  0  0  0  0  0  0\n    1.7310   -0.6820   -0.9750 C   0  0  0  0  0  0  0  0  0  0  0  0\n    2.3620   -1.3530   -0.0430 C   0  0  0  0  0  0  0  0  0  0  0  0\n    1.5810   -2.1310    0.9840 C   0  0  0  0  0  0  0  0  0  0  0  0\n    3.8680   -1.3460    0.0020 C   0  0  1  0  0  0  0  0  0  0  0  0\n    4.3450   -0.2630    0.9710 C   0  0  1  0  0  0  0  0  0  0  0  0\n    5.8510   -0.2560    1.0160 C   0  0  0  0  0  0  0  0  0  0  0  0\n    6.5090    0.8490    0.7660 C   0  0  0  0  0  0  0  0  0  0  0  0\n    8.0040    0.8930    0.9500 C   0  0  1  0  0  0  0  0  0  0  0  0\n    8.6920    0.6130   -0.3870 C   0  0  1  0  0  0  0  0  0  0  0  0\n   10.1870    0.6580   -0.2030 C   0  0  0  0  0  0  0  0  0  0  0  0\n   10.9280   -0.3400   -0.6180 C   0  0  0  0  0  0  0  0  0  0  0  0\n   12.3990   -0.3720   -0.2920 C   0  0  0  0  0  0  0  0  0  0  0  0\n   10.3100   -1.4540   -1.4220 C   0  0  0  0  0  0  0  0  0  0  0  0\n    5.7710    2.0750    0.2940 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -9.7650    0.9420   -2.2490 H   0  0  0  0  0  0  0  0  0  0  0  0\n  -11.1100    1.9820   -1.7240 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -9.6340    1.8680   -0.7350 H   0  0  0  0  0  0  0  0  0  0  0  0\n  -12.9070   -0.3760   -1.1600 H   0  0  0  0  0  0  0  0  0  0  0  0\n  -12.5720   -0.4050    0.5880 H   0  0  0  0  0  0  0  0  0  0  0  0\n  -12.7660    1.1500   -0.2550 H   0  0  0  0  0  0  0  0  0  0  0  0\n  -10.5840   -1.6860    0.2520 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -8.3180   -1.4950   -1.0810 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -8.3010   -0.1640    1.6660 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -6.3750   -2.8790    0.1650 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.1100   -1.8280   -0.5160 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0130   -2.3520    1.1820 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -6.4270    1.1840    1.2280 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.9640    0.5900    1.9540 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.3060    1.1990   -1.0180 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -2.3590    2.7400    1.6570 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.9350    1.6910    1.4490 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.1370    3.1320    0.4230 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -2.3040    0.3100   -1.7730 H   0  0  0  0  0  0  0  0  0  0  0  0\n    0.1290    1.3170   -1.8640 H   0  0  0  0  0  0  0  0  0  0  0  0\n    0.1080    1.3000   -0.0840 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.1600   -1.1650   -0.1110 H   0  0  0  0  0  0  0  0  0  0  0  0\n    2.2910   -0.1510   -1.7300 H   0  0  0  0  0  0  0  0  0  0  0  0\n    1.3420   -3.1180    0.5880 H   0  0  0  0  0  0  0  0  0  0  0  0\n    2.1780   -2.2380    1.8900 H   0  0  0  0  0  0  0  0  0  0  0  0\n    0.6580   -1.6000    1.2180 H   0  0  0  0  0  0  0  0  0  0  0  0\n    4.2260   -2.3190    0.3400 H   0  0  0  0  0  0  0  0  0  0  0  0\n    3.9870    0.7100    0.6330 H   0  0  0  0  0  0  0  0  0  0  0  0\n    6.3880   -1.1630    1.2530 H   0  0  0  0  0  0  0  0  0  0  0  0\n    8.2970    1.8800    1.3090 H   0  0  0  0  0  0  0  0  0  0  0  0\n    8.3990   -0.3740   -0.7470 H   0  0  0  0  0  0  0  0  0  0  0  0\n    8.3920    1.3680   -1.1150 H   0  0  0  0  0  0  0  0  0  0  0  0\n   10.6470    1.5120    0.2710 H   0  0  0  0  0  0  0  0  0  0  0  0\n   12.5500   -0.8920    0.6540 H   0  0  0  0  0  0  0  0  0  0  0  0\n   12.9350   -0.8950   -1.0840 H   0  0  0  0  0  0  0  0  0  0  0  0\n   12.7750    0.6480   -0.2100 H   0  0  0  0  0  0  0  0  0  0  0  0\n    9.2710   -1.2100   -1.6430 H   0  0  0  0  0  0  0  0  0  0  0  0\n   10.8610   -1.5790   -2.3540 H   0  0  0  0  0  0  0  0  0  0  0  0\n   10.3510   -2.3810   -0.8490 H   0  0  0  0  0  0  0  0  0  0  0  0\n    5.4010    2.6300    1.1560 H   0  0  0  0  0  0  0  0  0  0  0  0\n    6.4470    2.7070   -0.2820 H   0  0  0  0  0  0  0  0  0  0  0  0\n    4.9310    1.7750   -0.3320 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -8.3880    0.2570   -0.7760 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -8.2310   -1.9160    1.3610 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.9600   -0.6120    0.6400 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.3110    2.4010    0.2950 H   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.1390   -1.1480   -1.8910 H   0  0  0  0  0  0  0  0  0  0  0  0\n    4.2600   -1.1410   -0.9940 H   0  0  0  0  0  0  0  0  0  0  0  0\n    3.9530   -0.4680    1.9670 H   0  0  0  0  0  0  0  0  0  0  0  0\n    8.3030    0.1390    1.6780 H   0  0  0  0  0  0  0  0  0  0  0  0\n  3  2  1  0  0  0  0\n  1  2  1  0  0  0  0\n  2  4  2  3  0  0  0\n  4  5  1  0  0  0  0\n  5  6  1  0  0  0  0\n  6  7  1  0  0  0  0\n  8  7  1  0  0  0  0\n  7  9  2  0  0  0  0\n  9 10  1  0  0  0  0\n 10 11  1  0  0  0  0\n 11 12  1  0  0  0  0\n 13 12  1  0  0  0  0\n 12 14  2  0  0  0  0\n 14 15  1  0  0  0  0\n 15 16  1  0  0  0  0\n 16 17  1  0  0  0  0\n 17 18  2  0  0  0  0\n 18 19  1  0  0  0  0\n 18 20  1  0  0  0  0\n 20 21  1  0  0  0  0\n 21 22  1  0  0  0  0\n 22 23  2  0  0  0  0\n 23 30  1  0  0  0  0\n 23 24  1  0  0  0  0\n 24 25  1  0  0  0  0\n 25 26  1  0  0  0  0\n 26 27  2  3  0  0  0\n 27 29  1  0  0  0  0\n 27 28  1  0  0  0  0\n  1 31  1  0  0  0  0\n  1 32  1  0  0  0  0\n  1 33  1  0  0  0  0\n  3 34  1  0  0  0  0\n  3 35  1  0  0  0  0\n  3 36  1  0  0  0  0\n  4 37  1  0  0  0  0\n  5 38  1  0  0  0  0\n  6 39  1  0  0  0  0\n  8 40  1  0  0  0  0\n  8 41  1  0  0  0  0\n  8 42  1  0  0  0  0\n  9 43  1  0  0  0  0\n 10 44  1  0  0  0  0\n 11 45  1  0  0  0  0\n 13 46  1  0  0  0  0\n 13 47  1  0  0  0  0\n 13 48  1  0  0  0  0\n 14 49  1  0  0  0  0\n 15 50  1  0  0  0  0\n 15 51  1  0  0  0  0\n 16 52  1  0  0  0  0\n 17 53  1  0  0  0  0\n 19 54  1  0  0  0  0\n 19 55  1  0  0  0  0\n 19 56  1  0  0  0  0\n 20 57  1  0  0  0  0\n 21 58  1  0  0  0  0\n 22 59  1  0  0  0  0\n 24 60  1  0  0  0  0\n 25 61  1  0  0  0  0\n 25 62  1  0  0  0  0\n 26 63  1  0  0  0  0\n 28 64  1  0  0  0  0\n 28 65  1  0  0  0  0\n 28 66  1  0  0  0  0\n 29 67  1  0  0  0  0\n 29 68  1  0  0  0  0\n 29 69  1  0  0  0  0\n 30 70  1  0  0  0  0\n 30 71  1  0  0  0  0\n 30 72  1  0  0  0  0\n  5 73  1  0  0  0  0\n  6 74  1  0  0  0  0\n 10 75  1  0  0  0  0\n 11 76  1  0  0  0  0\n 16 77  1  0  0  0  0\n 20 78  1  0  0  0  0\n 21 79  1  0  0  0  0\n 24 80  1  0  0  0  0\nM  END\n</structure><type>mol</type><dimension>3D</dimension><defaultStructure>false</defaultStructure></ChemicalStructures><ChemicalStructures><structure>\n  Ketcher 05282116592D 1   1.00000     0.00000     0\n\n 30 29  0     0  0            999 V2000\n   -4.5490   -2.5073    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.4174   -3.0087    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.4174   -4.0117    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.5490   -4.5131    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.6804   -4.0117    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.6804   -3.0087    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -2.8118   -2.5073    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -2.8118   -4.5131    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.9433   -4.0117    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.9433   -3.0087    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.9433   -1.0029    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -2.8118   -1.5044    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.0748   -2.5073    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.0748   -1.5044    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.1210   -1.1944    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.1210   -2.8172    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    0.4685   -2.0058    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0504   -5.3817    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.8398   -5.2223    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -3.6804   -2.0058    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.1210   -0.1915    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -0.9895    0.3100    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    0.7476    0.3100    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    1.6162   -0.1915    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.8000   -2.1849    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    2.4847    0.3100    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    3.3533   -0.1915    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    4.2218    0.3100    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n    3.3533   -1.1944    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -1.2270   -3.5818    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  1  0     0  0\n  1  6  1  0     0  0\n  2  3  1  0     0  0\n  3  4  2  0     0  0\n  6  5  2  0     0  0\n  5  8  1  0     0  0\n  8  9  1  0     0  0\n  9 10  1  0     0  0\n  7 10  2  0     0  0\n 12  7  1  0     0  0\n 11 12  1  0     0  0\n 11 14  1  0     0  0\n 14 13  2  0     0  0\n 13 16  1  0     0  0\n 15 17  1  0     0  0\n 16 17  1  0     0  0\n  4 18  1  0     0  0\n  4 19  1  0     0  0\n  6 20  1  0     0  0\n 15 21  2  0     0  0\n 21 22  1  0     0  0\n 21 23  1  0     0  0\n 23 24  1  0     0  0\n 10 25  1  0     0  0\n 24 26  1  0     0  0\n 26 27  2  0     0  0\n 27 28  1  0     0  0\n 27 29  1  0     0  0\n 13 30  1  0     0  0\nM  END\n</structure><type>mol</type><dimension>2D</dimension><defaultStructure>false</defaultStructure></ChemicalStructures><DatabaseLinks><data>C00003755</data><type>KNApSAcK accession</type></DatabaseLinks><DatabaseLinks><data>C00751</data><type>KEGG COMPOUND accession</type></DatabaseLinks><DatabaseLinks><data>HMDB0000256</data><type>HMDB accession</type></DatabaseLinks><DatabaseLinks><data>LMPR0106010002</data><type>LIPID MAPS instance accession</type></DatabaseLinks><DatabaseLinks><data>SQL</data><type>PDBeChem accession</type></DatabaseLinks><DatabaseLinks><data>Squalene</data><type>Wikipedia accession</type></DatabaseLinks><DatabaseLinks><data>SQUALENE</data><type>MetaCyc accession</type></DatabaseLinks><OntologyParents><chebiName>Saccharomyces cerevisiae metabolite</chebiName><chebiId>CHEBI:75772</chebiId><type>has role</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyParents><OntologyParents><chebiName>human metabolite</chebiName><chebiId>CHEBI:77746</chebiId><type>has role</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyParents><OntologyParents><chebiName>mouse metabolite</chebiName><chebiId>CHEBI:75771</chebiId><type>has role</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyParents><OntologyParents><chebiName>plant metabolite</chebiName><chebiId>CHEBI:76924</chebiId><type>has role</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyParents><OntologyParents><chebiName>triterpene</chebiName><chebiId>CHEBI:35191</chebiId><type>is a</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyParents><OntologyChildren><chebiName>tetrahydroxysqualene</chebiName><chebiId>CHEBI:66216</chebiId><type>has parent hydride</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>(R)-12-hydroxysqualene</chebiName><chebiId>CHEBI:88123</chebiId><type>has parent hydride</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>squalene triterpenoid</chebiName><chebiId>CHEBI:26747</chebiId><type>has parent hydride</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>3-methyl-1,2-didehydro-2,3-dihydrosqualene</chebiName><chebiId>CHEBI:70860</chebiId><type>has functional parent</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>(S)-2,3-epoxysqualene</chebiName><chebiId>CHEBI:15441</chebiId><type>has parent hydride</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>3,22-dimethyl-1,2,23,24-tetradehydro-2,3,22,23-tetrahydrosqualene</chebiName><chebiId>CHEBI:70861</chebiId><type>has functional parent</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><OntologyChildren><chebiName>2,3-epoxysqualene</chebiName><chebiId>CHEBI:78662</chebiId><type>has parent hydride</type><status>CHECKED</status><cyclicRelationship>false</cyclicRelationship></OntologyChildren><GeneralComments><text>Squalene is the biochemical precursor to the whole family of steroids. Oxidation (via squalene monooxygenase) of one of the terminal double bonds of squalene yields 2,3-squalene oxide, which undergoes enzyme-catalyzed cyclization to afford lanosterol, which is then elaborated into cholesterol and other steroids (Wikipedia).</text><date>2011-04-06</date></GeneralComments><CompoundOrigins><speciesText>Rubia yunnanensis</speciesText><speciesAccession>IPNI:765385-1</speciesAccession><componentText>root</componentText><componentAccession>BTO:0001188</componentAccession><SourceType>PubMed Id</SourceType><SourceAccession>21973054</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Mus musculus</speciesText><speciesAccession>NCBI:txid10090</speciesAccession><SourceType>PubMed Id</SourceType><SourceAccession>19425150</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Centella asiatica</speciesText><speciesAccession>NCBI:txid48106</speciesAccession><SourceType>MetaboLights</SourceType><SourceAccession>MTBLS175</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Centella asiatica</speciesText><speciesAccession>NCBI:txid48106</speciesAccession><SourceType>MetaboLights</SourceType><SourceAccession>MTBLS175</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Saccharomyces cerevisiae</speciesText><speciesAccession>NCBI:txid4932</speciesAccession><SourceType>PubMed Id</SourceType><SourceAccession>24678285</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Homo sapiens</speciesText><speciesAccession>NCBI:txid9606</speciesAccession><SourceType>DOI</SourceType><SourceAccession>10.1038/nbt.2488</SourceAccession></CompoundOrigins><CompoundOrigins><speciesText>Homo sapiens</speciesText><speciesAccession>NCBI:txid9606</speciesAccession><componentText>blood</componentText><componentAccession>UBERON:0000178</componentAccession><SourceType>PubMed Id</SourceType><SourceAccession>10487487</SourceAccession></CompoundOrigins></return></getCompleteEntityResponse></S:Body></S:Envelope>"

For building a POST request, see the documentation of the Request class.

Using a custom rule

If no scheduling rule exists for a host name, sched uses a default rule of three requests per second (this default frequency may be changed when creating the Scheduler instance).

To define a custom rule for a host name, use the setRule() method:

scheduler$setRule("www.ebi.ac.uk", n = 7, lap = 2)

This call defines a new rule for domain www.ebi.ac.uk, that limits the number of request to 7 every 2 seconds. Note that the time lap is a sliding window, and sched registers the time of the requests. So supposing 7 requests have already been run during the 2 seconds, the 8th request will be blocked, but only until the first one becomes 2 seconds old.

To delete all defined rules, even the ones created automatically by sched, run:

scheduler$deleteRules()

Downloading a file from a URL

With sched it is also possible to download file directly from URLs and write them to disk.

For this demonstration, we will use a destination folder:

my_temp_dir <- file.path(tempdir(), "my_temp_folder_for_sched_vignette")

To download a file from a URL and write it directly on disk, use the downloadFile() method:

my_url <- sched::URL$new(
  "https://gitlab.com/cnrgh/databases/r-sched/-/raw/main/README.md"
)
dst <- file.path(my_temp_dir, "readme.md")
scheduler$downloadFile(my_url, dest_file = dst)

As with the sendRequest() method, the scheduler will use rules to limit access frequency to the domain name.

Removal of the temporary folder:

unlink(my_temp_dir, recursive = TRUE)

mirror server hosted at Truenetwork, Russian Federation.