purrr/ 0000755 0001762 0000144 00000000000 13646316237 011437 5 ustar ligges users purrr/NAMESPACE 0000644 0001762 0000144 00000010214 13646143666 012660 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(as_mapper,character)
S3method(as_mapper,default)
S3method(as_mapper,list)
S3method(as_mapper,numeric)
S3method(modify,character)
S3method(modify,default)
S3method(modify,double)
S3method(modify,integer)
S3method(modify,logical)
S3method(modify,pairlist)
S3method(modify2,character)
S3method(modify2,default)
S3method(modify2,double)
S3method(modify2,integer)
S3method(modify2,logical)
S3method(modify_at,character)
S3method(modify_at,default)
S3method(modify_at,double)
S3method(modify_at,integer)
S3method(modify_at,logical)
S3method(modify_depth,default)
S3method(modify_if,character)
S3method(modify_if,default)
S3method(modify_if,double)
S3method(modify_if,integer)
S3method(modify_if,logical)
S3method(print,purrr_function_compose)
S3method(print,purrr_function_partial)
S3method(print,purrr_rate_backoff)
S3method(print,purrr_rate_delay)
S3method(rate_sleep,purrr_rate_backoff)
S3method(rate_sleep,purrr_rate_delay)
export("%>%")
export("%@%")
export("%||%")
export("pluck<-")
export(accumulate)
export(accumulate2)
export(accumulate_right)
export(array_branch)
export(array_tree)
export(as_function)
export(as_mapper)
export(as_vector)
export(assign_in)
export(at_depth)
export(attr_getter)
export(auto_browse)
export(chuck)
export(compact)
export(compose)
export(cross)
export(cross2)
export(cross3)
export(cross_d)
export(cross_df)
export(cross_n)
export(detect)
export(detect_index)
export(discard)
export(done)
export(every)
export(exec)
export(flatten)
export(flatten_chr)
export(flatten_dbl)
export(flatten_df)
export(flatten_dfc)
export(flatten_dfr)
export(flatten_int)
export(flatten_lgl)
export(flatten_raw)
export(has_element)
export(head_while)
export(imap)
export(imap_chr)
export(imap_dbl)
export(imap_dfc)
export(imap_dfr)
export(imap_int)
export(imap_lgl)
export(imap_raw)
export(imodify)
export(insistently)
export(invoke)
export(invoke_map)
export(invoke_map_chr)
export(invoke_map_dbl)
export(invoke_map_df)
export(invoke_map_dfc)
export(invoke_map_dfr)
export(invoke_map_int)
export(invoke_map_lgl)
export(invoke_map_raw)
export(is_atomic)
export(is_bare_atomic)
export(is_bare_character)
export(is_bare_double)
export(is_bare_integer)
export(is_bare_list)
export(is_bare_logical)
export(is_bare_numeric)
export(is_bare_vector)
export(is_character)
export(is_double)
export(is_empty)
export(is_formula)
export(is_function)
export(is_integer)
export(is_list)
export(is_logical)
export(is_null)
export(is_numeric)
export(is_rate)
export(is_scalar_atomic)
export(is_scalar_character)
export(is_scalar_double)
export(is_scalar_integer)
export(is_scalar_list)
export(is_scalar_logical)
export(is_scalar_numeric)
export(is_scalar_vector)
export(is_vector)
export(iwalk)
export(keep)
export(lift)
export(lift_dl)
export(lift_dv)
export(lift_ld)
export(lift_lv)
export(lift_vd)
export(lift_vl)
export(list_along)
export(list_merge)
export(list_modify)
export(lmap)
export(lmap_at)
export(lmap_if)
export(map)
export(map2)
export(map2_chr)
export(map2_dbl)
export(map2_df)
export(map2_dfc)
export(map2_dfr)
export(map2_int)
export(map2_lgl)
export(map2_raw)
export(map_at)
export(map_call)
export(map_chr)
export(map_dbl)
export(map_depth)
export(map_df)
export(map_dfc)
export(map_dfr)
export(map_if)
export(map_int)
export(map_lgl)
export(map_raw)
export(modify)
export(modify2)
export(modify_at)
export(modify_depth)
export(modify_if)
export(modify_in)
export(negate)
export(none)
export(partial)
export(pluck)
export(pmap)
export(pmap_chr)
export(pmap_dbl)
export(pmap_df)
export(pmap_dfc)
export(pmap_dfr)
export(pmap_int)
export(pmap_lgl)
export(pmap_raw)
export(possibly)
export(prepend)
export(pwalk)
export(quietly)
export(rate_backoff)
export(rate_delay)
export(rate_reset)
export(rate_sleep)
export(rbernoulli)
export(rdunif)
export(reduce)
export(reduce2)
export(reduce2_right)
export(reduce_right)
export(rep_along)
export(rerun)
export(safely)
export(set_names)
export(simplify)
export(simplify_all)
export(slowly)
export(some)
export(splice)
export(tail_while)
export(transpose)
export(update_list)
export(vec_depth)
export(walk)
export(walk2)
export(when)
export(zap)
import(rlang)
importFrom(magrittr,"%>%")
useDynLib(purrr, .registration = TRUE)
purrr/LICENSE 0000644 0001762 0000144 00000104513 13630736102 012436 0 ustar ligges users GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
purrr/README.md 0000644 0001762 0000144 00000005376 13646111165 012722 0 ustar ligges users
# purrr
[](https://cran.r-project.org/package=purrr)
[](https://github.com/tidyverse/purrr)
[](https://codecov.io/gh/tidyverse/purrr?branch=master)
## Overview
purrr enhances R’s functional programming (FP) toolkit by providing a
complete and consistent set of tools for working with functions and
vectors. If you’ve never heard of FP before, the best place to start is
the family of `map()` functions which allow you to replace many for
loops with code that is both more succinct and easier to read. The best
place to learn about the `map()` functions is the [iteration
chapter](http://r4ds.had.co.nz/iteration.html) in R for data science.
## Installation
``` r
# The easiest way to get purrr is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just purrr:
install.packages("purrr")
# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/purrr")
```
## Cheatsheet
## Usage
The following example uses purrr to solve a fairly realistic problem:
split a data frame into pieces, fit a model to each piece, compute the
summary, then extract the R2.
``` r
library(purrr)
mtcars %>%
split(.$cyl) %>% # from base R
map(~ lm(mpg ~ wt, data = .)) %>%
map(summary) %>%
map_dbl("r.squared")
#> 4 6 8
#> 0.5086326 0.4645102 0.4229655
```
This example illustrates some of the advantages of purrr functions over
the equivalents in base R:
- The first argument is always the data, so purrr works naturally with
the pipe.
- All purrr functions are type-stable. They always return the
advertised output type (`map()` returns lists; `map_dbl()` returns
double vectors), or they throw an error.
- All `map()` functions either accept function, formulas (used for
succinctly generating anonymous functions), a character vector (used
to extract components by name), or a numeric vector (used to extract
by position).
-----
Please note that this project is released with a [Contributor Code of
Conduct](https://purrr.tidyverse.org/CODE_OF_CONDUCT). By participating
in this project you agree to abide by its terms.
purrr/man/ 0000755 0001762 0000144 00000000000 13630741543 012205 5 ustar ligges users purrr/man/list_modify.Rd 0000644 0001762 0000144 00000003215 13630736102 015012 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/list-modify.R
\name{list_modify}
\alias{list_modify}
\alias{list_merge}
\alias{update_list}
\title{Modify a list}
\usage{
list_modify(.x, ...)
list_merge(.x, ...)
}
\arguments{
\item{.x}{List to modify.}
\item{...}{New values of a list. Use \code{zap()} to remove values.
These values should be either all named or all unnamed. When
inputs are all named, they are matched to \code{.x} by name. When they
are all unnamed, they are matched positionally.
These dots support \link[rlang:list2]{tidy dots} features. In
particular, if your functions are stored in a list, you can
splice that in with \verb{!!!}.}
}
\description{
\code{list_modify()} and \code{list_merge()} recursively combine two lists, matching
elements either by name or position. If a sub-element is present in
both lists \code{list_modify()} takes the value from \code{y}, and \code{list_merge()}
concatenates the values together.
\code{update_list()} handles formulas and quosures that can refer to
values existing within the input list. Note that this function
might be deprecated in the future in favour of a \code{dplyr::mutate()}
method for lists.
}
\examples{
x <- list(x = 1:10, y = 4, z = list(a = 1, b = 2))
str(x)
# Update values
str(list_modify(x, a = 1))
# Replace values
str(list_modify(x, z = 5))
str(list_modify(x, z = list(a = 1:5)))
# Remove values
str(list_modify(x, z = zap()))
# Combine values
str(list_merge(x, x = 11, z = list(a = 2:5, c = 3)))
# All these functions support tidy dots features. Use !!! to splice
# a list of arguments:
l <- list(new = 1, y = zap(), z = 5)
str(list_modify(x, !!!l))
}
purrr/man/array-coercion.Rd 0000644 0001762 0000144 00000003727 13630736102 015415 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arrays.R
\name{array-coercion}
\alias{array-coercion}
\alias{array_branch}
\alias{array_tree}
\title{Coerce array to list}
\usage{
array_branch(array, margin = NULL)
array_tree(array, margin = NULL)
}
\arguments{
\item{array}{An array to coerce into a list.}
\item{margin}{A numeric vector indicating the positions of the
indices to be to be enlisted. If \code{NULL}, a full margin is
used. If \code{numeric(0)}, the array as a whole is wrapped in a
list.}
}
\description{
\code{array_branch()} and \code{array_tree()} enable arrays to be
used with purrr's functionals by turning them into lists. The
details of the coercion are controlled by the \code{margin}
argument. \code{array_tree()} creates an hierarchical list (a tree)
that has as many levels as dimensions specified in \code{margin},
while \code{array_branch()} creates a flat list (by analogy, a
branch) along all mentioned dimensions.
}
\details{
When no margin is specified, all dimensions are used by
default. When \code{margin} is a numeric vector of length zero, the
whole array is wrapped in a list.
}
\examples{
# We create an array with 3 dimensions
x <- array(1:12, c(2, 2, 3))
# A full margin for such an array would be the vector 1:3. This is
# the default if you don't specify a margin
# Creating a branch along the full margin is equivalent to
# as.list(array) and produces a list of size length(x):
array_branch(x) \%>\% str()
# A branch along the first dimension yields a list of length 2
# with each element containing a 2x3 array:
array_branch(x, 1) \%>\% str()
# A branch along the first and third dimensions yields a list of
# length 2x3 whose elements contain a vector of length 2:
array_branch(x, c(1, 3)) \%>\% str()
# Creating a tree from the full margin creates a list of lists of
# lists:
array_tree(x) \%>\% str()
# The ordering and the depth of the tree are controlled by the
# margin argument:
array_tree(x, c(3, 1)) \%>\% str()
}
purrr/man/zap.Rd 0000644 0001762 0000144 00000000510 13630736102 013255 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reexport-rlang.R
\docType{import}
\name{zap}
\alias{zap}
\title{Zap an element}
\description{
These objects are imported from other packages. Follow the links
below to see their documentation.
\describe{
\item{rlang}{\code{\link[rlang]{zap}}}
}}
purrr/man/modify_in.Rd 0000644 0001762 0000144 00000003112 13630736102 014441 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/modify.R
\name{modify_in}
\alias{modify_in}
\alias{assign_in}
\title{Modify a pluck location}
\usage{
modify_in(.x, .where, .f, ...)
assign_in(x, where, value)
}
\arguments{
\item{.x}{A vector or environment}
\item{.where, where}{A pluck location, as a numeric vector of
positions, a character vector of names, or a list combining both.
The location must exist in the data structure.}
\item{.f}{A function to apply at the pluck location given by \code{.where}.}
\item{...}{Arguments passed to \code{.f}.}
\item{x}{A vector or environment}
\item{value}{A value to replace in \code{.x} at the pluck location.}
}
\description{
\itemize{
\item \code{assign_in()} takes a data structure and a \link{pluck} location,
assigns a value there, and returns the modified data structure.
\item \code{modify_in()} applies a function to a pluck location, assigns the
result back to that location with \code{\link[=assign_in]{assign_in()}}, and returns the
modified data structure.
}
The pluck location must exist.
}
\examples{
# Recall that pluck() returns a component of a data structure that
# might be arbitrarily deep
x <- list(list(bar = 1, foo = 2))
pluck(x, 1, "foo")
# Use assign_in() to modify the pluck location:
assign_in(x, list(1, "foo"), 100)
# modify_in() applies a function to that location and update the
# element in place:
modify_in(x, list(1, "foo"), ~ .x * 200)
# Additional arguments are passed to the function in the ordinary way:
modify_in(x, list(1, "foo"), `+`, 100)
}
\seealso{
\code{\link[=pluck]{pluck()}}
}
purrr/man/rate_sleep.Rd 0000644 0001762 0000144 00000001411 13630736102 014607 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rate.R
\name{rate_sleep}
\alias{rate_sleep}
\alias{rate_reset}
\title{Wait for a given time}
\usage{
rate_sleep(rate, quiet = TRUE)
rate_reset(rate)
}
\arguments{
\item{rate}{A \link[=rate_backoff]{rate} object determining the waiting time.}
\item{quiet}{If \code{FALSE}, prints a message displaying how long until
the next request.}
}
\description{
If the rate's internal counter exceeds the maximum number of times
it is allowed to sleep, \code{rate_sleep()} throws an error of class
\code{purrr_error_rate_excess}.
}
\details{
Call \code{rate_reset()} to reset the internal rate counter to 0.
}
\seealso{
\code{\link[=rate_backoff]{rate_backoff()}}, \code{\link[=insistently]{insistently()}}
}
purrr/man/reduce_right.Rd 0000644 0001762 0000144 00000003344 13630736102 015137 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reduce.R
\name{reduce_right}
\alias{reduce_right}
\alias{reduce2_right}
\alias{accumulate_right}
\title{Reduce from the right (retired)}
\usage{
reduce_right(.x, .f, ..., .init)
reduce2_right(.x, .y, .f, ..., .init)
accumulate_right(.x, .f, ..., .init)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.f}{For \code{reduce()}, and \code{accumulate()}, a 2-argument
function. The function will be passed the accumulated value as
the first argument and the "next" value as the second argument.
For \code{reduce2()} and \code{accumulate2()}, a 3-argument function. The
function will be passed the accumulated value as the first
argument, the next value of \code{.x} as the second argument, and the
next value of \code{.y} as the third argument.
The reduction terminates early if \code{.f} returns a value wrapped in
a \code{\link[=done]{done()}}.}
\item{...}{Additional arguments passed on to the mapped function.}
\item{.init}{If supplied, will be used as the first value to start
the accumulation, rather than using \code{.x[[1]]}. This is useful if
you want to ensure that \code{reduce} returns a correct value when \code{.x}
is empty. If missing, and \code{.x} is empty, will throw an error.}
\item{.y}{For \code{reduce2()} and \code{accumulate2()}, an additional
argument that is passed to \code{.f}. If \code{init} is not set, \code{.y}
should be 1 element shorter than \code{.x}.}
}
\description{
\Sexpr[results=rd, stage=render]{purrr:::lifecycle("soft-deprecated")}
These functions are retired as of purrr 0.3.0. Please use the
\code{.dir} argument of \code{\link[=reduce]{reduce()}} instead, or reverse your vectors
and use a left reduction.
}
\keyword{internal}
purrr/man/as_vector.Rd 0000644 0001762 0000144 00000003222 13630736102 014453 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coercion.R
\name{as_vector}
\alias{as_vector}
\alias{simplify}
\alias{simplify_all}
\title{Coerce a list to a vector}
\usage{
as_vector(.x, .type = NULL)
simplify(.x, .type = NULL)
simplify_all(.x, .type = NULL)
}
\arguments{
\item{.x}{A list of vectors}
\item{.type}{A vector mold or a string describing the type of the
input vectors. The latter can be any of the types returned by
\code{\link[=typeof]{typeof()}}, or "numeric" as a shorthand for either
"double" or "integer".}
}
\description{
\code{as_vector()} collapses a list of vectors into one vector. It
checks that the type of each vector is consistent with
\code{.type}. If the list can not be simplified, it throws an error.
\code{simplify} will simplify a vector if possible; \code{simplify_all}
will apply \code{simplify} to every element of a list.
}
\details{
\code{.type} can be a vector mold specifying both the type and the
length of the vectors to be concatenated, such as \code{numeric(1)}
or \code{integer(4)}. Alternatively, it can be a string describing
the type, one of: "logical", "integer", "double", "complex",
"character" or "raw".
}
\examples{
# Supply the type either with a string:
as.list(letters) \%>\% as_vector("character")
# Or with a vector mold:
as.list(letters) \%>\% as_vector(character(1))
# Vector molds are more flexible because they also specify the
# length of the concatenated vectors:
list(1:2, 3:4, 5:6) \%>\% as_vector(integer(2))
# Note that unlike vapply(), as_vector() never adds dimension
# attributes. So when you specify a vector mold of size > 1, you
# always get a vector and not a matrix
}
purrr/man/negate.Rd 0000644 0001762 0000144 00000001542 13630736102 013734 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/negate.R
\name{negate}
\alias{negate}
\title{Negate a predicate function.}
\usage{
negate(.p)
}
\arguments{
\item{.p}{A single predicate function, a formula describing such a
predicate function, or a logical vector of the same length as \code{.x}.
Alternatively, if the elements of \code{.x} are themselves lists of
objects, a string indicating the name of a logical element in the
inner lists. Only those elements where \code{.p} evaluates to
\code{TRUE} will be modified.}
}
\value{
A new predicate function.
}
\description{
Negate a predicate function.
}
\examples{
negate("x")
negate(is.null)
negate(~ .x > 0)
x <- transpose(list(x = 1:10, y = rbernoulli(10)))
x \%>\% keep("y") \%>\% length()
x \%>\% keep(negate("y")) \%>\% length()
# Same as
x \%>\% discard("y") \%>\% length()
}
purrr/man/invoke.Rd 0000644 0001762 0000144 00000010612 13630736102 013762 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/retired-invoke.R
\name{invoke}
\alias{invoke}
\alias{invoke_map}
\alias{invoke_map_lgl}
\alias{invoke_map_int}
\alias{invoke_map_dbl}
\alias{invoke_map_chr}
\alias{invoke_map_raw}
\alias{invoke_map_dfr}
\alias{invoke_map_dfc}
\alias{invoke_map_df}
\alias{map_call}
\title{Invoke functions.}
\usage{
invoke(.f, .x = NULL, ..., .env = NULL)
invoke_map(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_lgl(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_int(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_dbl(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_chr(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_raw(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_dfr(.f, .x = list(NULL), ..., .env = NULL)
invoke_map_dfc(.f, .x = list(NULL), ..., .env = NULL)
}
\arguments{
\item{.f}{For \code{invoke}, a function; for \code{invoke_map} a
list of functions.}
\item{.x}{For \code{invoke}, an argument-list; for \code{invoke_map} a
list of argument-lists the same length as \code{.f} (or length 1).
The default argument, \code{list(NULL)}, will be recycled to the
same length as \code{.f}, and will call each function with no
arguments (apart from any supplied in \code{...}.}
\item{...}{Additional arguments passed to each function.}
\item{.env}{Environment in which \code{\link[=do.call]{do.call()}} should
evaluate a constructed expression. This only matters if you pass
as \code{.f} the name of a function rather than its value, or as
\code{.x} symbols of objects rather than their values.}
}
\description{
\Sexpr[results=rd, stage=render]{purrr:::lifecycle("retired")}
This pair of functions make it easier to combine a function and list
of parameters to get a result. \code{invoke} is a wrapper around
\code{do.call} that makes it easy to use in a pipe. \code{invoke_map}
makes it easier to call lists of functions with lists of parameters.
}
\section{Life cycle}{
These functions are retired in favour of \code{\link[=exec]{exec()}}. They are no
longer under active development but we will maintain them in the
package undefinitely.
\itemize{
\item \code{invoke()} is retired in favour of the simpler \code{exec()} function
reexported from rlang. \code{exec()} evaluates a function call built
from its inputs and supports tidy dots:\preformatted{# Before:
invoke(mean, list(na.rm = TRUE), x = 1:10)
# After
exec(mean, 1:10, !!!list(na.rm = TRUE))
}
\item \code{invoke_map()} is is retired without replacement because it is
more complex to understand than the corresponding code using
\code{map()}, \code{map2()} and \code{exec()}:\preformatted{# Before:
invoke_map(fns, list(args))
invoke_map(fns, list(args1, args2))
# After:
map(fns, exec, !!!args)
map2(fns, list(args1, args2), function(fn, args) exec(fn, !!!args))
}
}
}
\examples{
# Invoke a function with a list of arguments
invoke(runif, list(n = 10))
# Invoke a function with named arguments
invoke(runif, n = 10)
# Combine the two:
invoke(paste, list("01a", "01b"), sep = "-")
# That's more natural as part of a pipeline:
list("01a", "01b") \%>\%
invoke(paste, ., sep = "-")
# Invoke a list of functions, each with different arguments
invoke_map(list(runif, rnorm), list(list(n = 10), list(n = 5)))
# Or with the same inputs:
invoke_map(list(runif, rnorm), list(list(n = 5)))
invoke_map(list(runif, rnorm), n = 5)
# Or the same function with different inputs:
invoke_map("runif", list(list(n = 5), list(n = 10)))
# Or as a pipeline
list(m1 = mean, m2 = median) \%>\% invoke_map(x = rcauchy(100))
list(m1 = mean, m2 = median) \%>\% invoke_map_dbl(x = rcauchy(100))
# Note that you can also match by position by explicitly omitting `.x`.
# This can be useful when the argument names of the functions are not
# identical
list(m1 = mean, m2 = median) \%>\%
invoke_map(, rcauchy(100))
# If you have pairs of function name and arguments, it's natural
# to store them in a data frame. Here we use a tibble because
# it has better support for list-columns
if (rlang::is_installed("tibble")) {
df <- tibble::tibble(
f = c("runif", "rpois", "rnorm"),
params = list(
list(n = 10),
list(n = 5, lambda = 10),
list(n = 10, mean = -3, sd = 10)
)
)
df
invoke_map(df$f, df$params)
}
}
\seealso{
Other map variants:
\code{\link{imap}()},
\code{\link{lmap}()},
\code{\link{map2}()},
\code{\link{map_if}()},
\code{\link{map}()},
\code{\link{modify}()}
}
\concept{map variants}
\keyword{internal}
purrr/man/splice.Rd 0000644 0001762 0000144 00000001635 13630736102 013753 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/splice.R
\name{splice}
\alias{splice}
\title{Splice objects and lists of objects into a list}
\usage{
splice(...)
}
\arguments{
\item{...}{Objects to concatenate.}
}
\value{
A list.
}
\description{
\Sexpr[results=rd, stage=render]{purrr:::lifecycle("questioning")}
This splices all arguments into a list. Non-list objects and lists
with a S3 class are encapsulated in a list before concatenation.
}
\section{Life cycle}{
\code{splice()} is in the questioning lifecycle stage as of purrr
0.3.0. We are now favouring the \verb{!!!} syntax enabled by
\code{\link[rlang:list2]{rlang::list2()}}.
}
\examples{
inputs <- list(arg1 = "a", arg2 = "b")
# splice() concatenates the elements of inputs with arg3
splice(inputs, arg3 = c("c1", "c2")) \%>\% str()
list(inputs, arg3 = c("c1", "c2")) \%>\% str()
c(inputs, arg3 = c("c1", "c2")) \%>\% str()
}
purrr/man/purrr-package.Rd 0000644 0001762 0000144 00000001446 13646136151 015244 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/purrr.R
\docType{package}
\name{purrr-package}
\alias{purrr}
\alias{purrr-package}
\title{purrr: Functional Programming Tools}
\description{
\if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}}
A complete and consistent functional programming
toolkit for R.
}
\seealso{
Useful links:
\itemize{
\item \url{http://purrr.tidyverse.org}
\item \url{https://github.com/tidyverse/purrr}
\item Report bugs at \url{https://github.com/tidyverse/purrr/issues}
}
}
\author{
\strong{Maintainer}: Lionel Henry \email{lionel@rstudio.com}
Authors:
\itemize{
\item Hadley Wickham \email{hadley@rstudio.com}
}
Other contributors:
\itemize{
\item RStudio [copyright holder, funder]
}
}
\keyword{internal}
purrr/man/at_depth.Rd 0000644 0001762 0000144 00000003273 13630736102 014264 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/modify.R
\name{at_depth}
\alias{at_depth}
\title{Map at depth}
\usage{
at_depth(.x, .depth, .f, ...)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.depth}{Level of \code{.x} to map on. Use a negative value to
count up from the lowest level of the list.
\itemize{
\item \code{map_depth(x, 0, fun)} is equivalent to \code{fun(x)}.
\item \code{map_depth(x, 1, fun)} is equivalent to \code{x <- map(x, fun)}
\item \code{map_depth(x, 2, fun)} is equivalent to \code{x <- map(x, ~ map(., fun))}
}}
\item{.f}{A function, formula, or vector (not necessarily atomic).
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function. There
are three ways to refer to the arguments:
\itemize{
\item For a single argument function, use \code{.}
\item For a two argument function, use \code{.x} and \code{.y}
\item For more arguments, use \code{..1}, \code{..2}, \code{..3} etc
}
This syntax allows you to create very compact anonymous functions.
If \strong{character vector}, \strong{numeric vector}, or \strong{list}, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of \code{.default} will be returned.}
\item{...}{Additional arguments passed on to the mapped function.}
}
\description{
This function is defunct and has been replaced by \code{\link[=map_depth]{map_depth()}}.
See also \code{\link[=modify_depth]{modify_depth()}} for a version that preserves the types of
the elements of the tree.
}
\keyword{internal}
purrr/man/along.Rd 0000644 0001762 0000144 00000001314 13630741543 013573 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/along.R
\name{along}
\alias{along}
\alias{list_along}
\title{Create a list of given length}
\usage{
list_along(x)
}
\arguments{
\item{x}{A vector.}
}
\value{
A list of the same length as \code{x}.
}
\description{
\Sexpr[results=rd, stage=render]{purrr:::lifecycle("questioning")}
It can be useful to create an empty list that you plan to fill later. This is
similar to the idea of \code{\link[=seq_along]{seq_along()}}, which creates a vector of the same
length as its input.
}
\details{
This function might change to \code{\link[vctrs:vec_init]{vctrs::vec_init()}}.
}
\examples{
x <- 1:5
seq_along(x)
list_along(x)
}
\keyword{internal}
purrr/man/rdunif.Rd 0000644 0001762 0000144 00000000710 13630736102 013754 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{rdunif}
\alias{rdunif}
\title{Generate random sample from a discrete uniform distribution}
\usage{
rdunif(n, b, a = 1)
}
\arguments{
\item{n}{Number of samples to draw.}
\item{a, b}{Range of the distribution (inclusive).}
}
\description{
Generate random sample from a discrete uniform distribution
}
\examples{
table(rdunif(1e3, 10))
table(rdunif(1e3, 10, -5))
}
purrr/man/map.Rd 0000644 0001762 0000144 00000013314 13630741543 013253 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/map.R
\name{map}
\alias{map}
\alias{map_lgl}
\alias{map_chr}
\alias{map_int}
\alias{map_dbl}
\alias{map_raw}
\alias{map_dfr}
\alias{map_df}
\alias{map_dfc}
\alias{walk}
\title{Apply a function to each element of a list or atomic vector}
\usage{
map(.x, .f, ...)
map_lgl(.x, .f, ...)
map_chr(.x, .f, ...)
map_int(.x, .f, ...)
map_dbl(.x, .f, ...)
map_raw(.x, .f, ...)
map_dfr(.x, .f, ..., .id = NULL)
map_dfc(.x, .f, ...)
walk(.x, .f, ...)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.f}{A function, formula, or vector (not necessarily atomic).
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function. There
are three ways to refer to the arguments:
\itemize{
\item For a single argument function, use \code{.}
\item For a two argument function, use \code{.x} and \code{.y}
\item For more arguments, use \code{..1}, \code{..2}, \code{..3} etc
}
This syntax allows you to create very compact anonymous functions.
If \strong{character vector}, \strong{numeric vector}, or \strong{list}, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of \code{.default} will be returned.}
\item{...}{Additional arguments passed on to the mapped function.}
\item{.id}{Either a string or \code{NULL}. If a string, the output will contain
a variable with that name, storing either the name (if \code{.x} is named) or
the index (if \code{.x} is unnamed) of the input. If \code{NULL}, the default, no
variable will be created.
Only applies to \verb{_dfr} variant.}
}
\value{
\itemize{
\item \code{map()} Returns a list the same length as \code{.x}.
\item \code{map_lgl()} returns a logical vector, \code{map_int()} an integer
vector, \code{map_dbl()} a double vector, and \code{map_chr()} a character
vector.
\item \code{map_df()}, \code{map_dfc()}, \code{map_dfr()} all return a data frame.
\item If \code{.x} has \code{names()}, the return value preserves those names.
\item The output of \code{.f} will be automatically typed upwards, e.g.
logical -> integer -> double -> character.
}
\itemize{
\item \code{walk()} returns the input \code{.x} (invisibly). This makes it easy to
use in pipe.
}
}
\description{
The map functions transform their input by applying a function to
each element of a list or atomic vector and returning an object of the same length as the input.
\itemize{
\item \code{map()} always returns a list. See the \code{\link[=modify]{modify()}} family for
versions that return an object of the same type as the input.
\item \code{map_lgl()}, \code{map_int()}, \code{map_dbl()} and \code{map_chr()} return an
atomic vector of the indicated type (or die trying).
\item \code{map_dfr()} and \code{map_dfc()} return a data frame created by
row-binding and column-binding respectively. They require dplyr
to be installed.
\item The returned values of \code{.f} must be of length one for each element
of \code{.x}. If \code{.f} uses an extractor function shortcut, \code{.default}
can be specified to handle values that are absent or empty. See
\code{\link[=as_mapper]{as_mapper()}} for more on \code{.default}.
}
\itemize{
\item \code{walk()} calls \code{.f} for its side-effect and returns
the input \code{.x}.
}
}
\examples{
# Compute normal distributions from an atomic vector
1:10 \%>\%
map(rnorm, n = 10)
# You can also use an anonymous function
1:10 \%>\%
map(function(x) rnorm(10, x))
# Or a formula
1:10 \%>\%
map(~ rnorm(10, .x))
# Simplify output to a vector instead of a list by computing the mean of the distributions
1:10 \%>\%
map(rnorm, n = 10) \%>\% # output a list
map_dbl(mean) # output an atomic vector
# Using set_names() with character vectors is handy to keep track
# of the original inputs:
set_names(c("foo", "bar")) \%>\% map_chr(paste0, ":suffix")
# Working with lists
favorite_desserts <- list(Sophia = "banana bread", Eliott = "pancakes", Karina = "chocolate cake")
favorite_desserts \%>\% map_chr(~ paste(.x, "rocks!"))
# Extract by name or position
# .default specifies value for elements that are missing or NULL
l1 <- list(list(a = 1L), list(a = NULL, b = 2L), list(b = 3L))
l1 \%>\% map("a", .default = "???")
l1 \%>\% map_int("b", .default = NA)
l1 \%>\% map_int(2, .default = NA)
# Supply multiple values to index deeply into a list
l2 <- list(
list(num = 1:3, letters[1:3]),
list(num = 101:103, letters[4:6]),
list()
)
l2 \%>\% map(c(2, 2))
# Use a list to build an extractor that mixes numeric indices and names,
# and .default to provide a default value if the element does not exist
l2 \%>\% map(list("num", 3))
l2 \%>\% map_int(list("num", 3), .default = NA)
# Working with data frames
# Use map_lgl(), map_dbl(), etc to return a vector instead of a list:
mtcars \%>\% map_dbl(sum)
# A more realistic example: split a data frame into pieces, fit a
# model to each piece, summarise and extract R^2
mtcars \%>\%
split(.$cyl) \%>\%
map(~ lm(mpg ~ wt, data = .x)) \%>\%
map(summary) \%>\%
map_dbl("r.squared")
# If each element of the output is a data frame, use
# map_dfr to row-bind them together:
mtcars \%>\%
split(.$cyl) \%>\%
map(~ lm(mpg ~ wt, data = .x)) \%>\%
map_dfr(~ as.data.frame(t(as.matrix(coef(.)))))
# (if you also want to preserve the variable names see
# the broom package)
}
\seealso{
\code{\link[=map_if]{map_if()}} for applying a function to only those elements
of \code{.x} that meet a specified condition.
Other map variants:
\code{\link{imap}()},
\code{\link{invoke}()},
\code{\link{lmap}()},
\code{\link{map2}()},
\code{\link{map_if}()},
\code{\link{modify}()}
}
\concept{map variants}
purrr/man/every.Rd 0000644 0001762 0000144 00000001745 13630736102 013630 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/every-some-none.R
\name{every}
\alias{every}
\alias{some}
\alias{none}
\title{Do every, some, or none of the elements of a list satisfy a predicate?}
\usage{
every(.x, .p, ...)
some(.x, .p, ...)
none(.x, .p, ...)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.p}{A predicate function to apply on each element of \code{.x}.
\code{some()} returns \code{TRUE} when \code{.p} is \code{TRUE} for at least one
element. \code{every()} returns \code{TRUE} when \code{.p} is \code{TRUE} for all
elements. \code{none()} returns \code{TRUE} when \code{.p} is \code{FALSE} for all
elements.`}
\item{...}{Additional arguments passed on to \code{.p}.}
}
\value{
A logical vector of length 1.
}
\description{
Do every, some, or none of the elements of a list satisfy a predicate?
}
\examples{
y <- list(0:10, 5.5)
y \%>\% every(is.numeric)
y \%>\% every(is.integer)
y \%>\% some(is.integer)
y \%>\% none(is.character)
}
purrr/man/transpose.Rd 0000644 0001762 0000144 00000003735 13630736102 014515 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/transpose.R
\name{transpose}
\alias{transpose}
\title{Transpose a list.}
\usage{
transpose(.l, .names = NULL)
}
\arguments{
\item{.l}{A list of vectors to transpose. The first element is used as the
template; you'll get a warning if a subsequent element has a different
length.}
\item{.names}{For efficiency, \code{transpose()} bases the return structure on
the first component of \code{.l} by default. Specify \code{.names} to override this.}
}
\value{
A list with indexing transposed compared to \code{.l}.
}
\description{
Transpose turns a list-of-lists "inside-out"; it turns a pair of lists into a
list of pairs, or a list of pairs into pair of lists. For example,
if you had a list of length n where each component had values \code{a} and
\code{b}, \code{transpose()} would make a list with elements \code{a} and
\code{b} that contained lists of length n. It's called transpose because
\code{x[[1]][[2]]} is equivalent to \code{transpose(x)[[2]][[1]]}.
}
\details{
Note that \code{transpose()} is its own inverse, much like the
transpose operation on a matrix. You can get back the original
input by transposing it twice.
}
\examples{
x <- rerun(5, x = runif(1), y = runif(5))
x \%>\% str()
x \%>\% transpose() \%>\% str()
# Back to where we started
x \%>\% transpose() \%>\% transpose() \%>\% str()
# transpose() is useful in conjunction with safely() & quietly()
x <- list("a", 1, 2)
y <- x \%>\% map(safely(log))
y \%>\% str()
y \%>\% transpose() \%>\% str()
# Use simplify_all() to reduce to atomic vectors where possible
x <- list(list(a = 1, b = 2), list(a = 3, b = 4), list(a = 5, b = 6))
x \%>\% transpose()
x \%>\% transpose() \%>\% simplify_all()
# Provide explicit component names to prevent loss of those that don't
# appear in first component
ll <- list(
list(x = 1, y = "one"),
list(z = "deux", x = 2)
)
ll \%>\% transpose()
nms <- ll \%>\% map(names) \%>\% reduce(union)
ll \%>\% transpose(.names = nms)
}
purrr/man/rbernoulli.Rd 0000644 0001762 0000144 00000000702 13630736102 014643 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{rbernoulli}
\alias{rbernoulli}
\title{Generate random sample from a Bernoulli distribution}
\usage{
rbernoulli(n, p = 0.5)
}
\arguments{
\item{n}{Number of samples}
\item{p}{Probability of getting \code{TRUE}}
}
\value{
A logical vector
}
\description{
Generate random sample from a Bernoulli distribution
}
\examples{
rbernoulli(10)
rbernoulli(100, 0.1)
}
purrr/man/when.Rd 0000644 0001762 0000144 00000003074 13630736102 013434 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/when.R
\name{when}
\alias{when}
\title{Match/validate a set of conditions for an object and continue with the action
associated with the first valid match.}
\usage{
when(., ...)
}
\arguments{
\item{.}{the value to match against}
\item{...}{formulas; each containing a condition as LHS and an action as RHS.
named arguments will define additional values.}
}
\value{
The value resulting from the action of the first valid
match/condition is returned. If no matches are found, and no default is
given, NULL will be returned.
Validity of the conditions are tested with \code{isTRUE}, or equivalently
with \code{identical(condition, TRUE)}.
In other words conditions resulting in more than one logical will never
be valid. Note that the input value is always treated as a single object,
as opposed to the \code{ifelse} function.
}
\description{
\code{when} is a flavour of pattern matching (or an if-else abstraction) in
which a value is matched against a sequence of condition-action sets. When a
valid match/condition is found the action is executed and the result of the
action is returned.
}
\examples{
1:10 \%>\%
when(
sum(.) <= 50 ~ sum(.),
sum(.) <= 100 ~ sum(.)/2,
~ 0
)
1:10 \%>\%
when(
sum(.) <= x ~ sum(.),
sum(.) <= 2*x ~ sum(.)/2,
~ 0,
x = 60
)
iris \%>\%
subset(Sepal.Length > 10) \%>\%
when(
nrow(.) > 0 ~ .,
~ iris \%>\% head(10)
)
iris \%>\%
head \%>\%
when(nrow(.) < 10 ~ .,
~ stop("Expected fewer than 10 rows."))
}
\keyword{internal}
purrr/man/get-attr.Rd 0000644 0001762 0000144 00000001111 13630736102 014210 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{get-attr}
\alias{get-attr}
\alias{\%@\%}
\title{Infix attribute accessor}
\usage{
x \%@\% name
}
\arguments{
\item{x}{Object}
\item{name}{Attribute name}
}
\description{
\Sexpr[results=rd, stage=render]{purrr:::lifecycle("soft-deprecated")}
Please use the \verb{\%@\%} operator exported in rlang. It has an
interface more consistent with \code{@}: uses NSE, supports S4 fields,
and has an assignment variant.
}
\examples{
factor(1:3) \%@\% "levels"
mtcars \%@\% "class"
}
\keyword{internal}
purrr/man/pluck.Rd 0000644 0001762 0000144 00000007667 13646111347 013632 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pluck.R
\name{pluck}
\alias{pluck}
\alias{chuck}
\alias{pluck<-}
\title{Pluck or chuck a single element from a vector or environment}
\usage{
pluck(.x, ..., .default = NULL)
chuck(.x, ...)
pluck(.x, ...) <- value
}
\arguments{
\item{.x, x}{A vector or environment}
\item{...}{A list of accessors for indexing into the object. Can be
an integer position, a string name, or an accessor function
(except for the assignment variants which only support names and
positions). If the object being indexed is an S4 object,
accessing it by name will return the corresponding slot.
These dots support \link[rlang:list2]{tidy dots} features. In
particular, if your accessors are stored in a list, you can
splice that in with \verb{!!!}.}
\item{.default}{Value to use if target is empty or absent.}
\item{value}{A value to replace in \code{.x} at the pluck location.}
}
\description{
\code{pluck()} and \code{chuck()} implement a generalised form of \code{[[} that
allow you to index deeply and flexibly into data structures.
\code{pluck()} consistently returns \code{NULL} when an element does not
exist, \code{chuck()} always throws an error in that case.
}
\details{
\itemize{
\item You can pluck or chuck with standard accessors like integer
positions and string names, and also accepts arbitrary accessor
functions, i.e. functions that take an object and return some
internal piece.
This is often more readable than a mix of operators and accessors
because it reads linearly and is free of syntactic
cruft. Compare: \code{accessor(x[[1]])$foo} to \code{pluck(x, 1, accessor, "foo")}.
\item These accessors never partial-match. This is unlike \code{$} which
will select the \code{disp} object if you write \code{mtcars$di}.
}
}
\examples{
# Let's create a list of data structures:
obj1 <- list("a", list(1, elt = "foo"))
obj2 <- list("b", list(2, elt = "bar"))
x <- list(obj1, obj2)
# pluck() provides a way of retrieving objects from such data
# structures using a combination of numeric positions, vector or
# list names, and accessor functions.
# Numeric positions index into the list by position, just like `[[`:
pluck(x, 1)
x[[1]]
pluck(x, 1, 2)
x[[1]][[2]]
# Supply names to index into named vectors:
pluck(x, 1, 2, "elt")
x[[1]][[2]][["elt"]]
# By default, pluck() consistently returns `NULL` when an element
# does not exist:
pluck(x, 10)
try(x[[10]])
# You can also supply a default value for non-existing elements:
pluck(x, 10, .default = NA)
# If you prefer to consistently fail for non-existing elements, use
# the opinionated variant chuck():
chuck(x, 1)
try(chuck(x, 10))
try(chuck(x, 1, 10))
# The map() functions use pluck() by default to retrieve multiple
# values from a list:
map(x, 2)
# Pass multiple indexes with a list:
map(x, list(2, "elt"))
# This is equivalent to:
map(x, pluck, 2, "elt")
# You can also supply a default:
map(x, list(2, "elt", 10), .default = "superb default")
# Or use the strict variant:
try(map(x, chuck, 2, "elt", 10))
# You can also assign a value in a pluck location with pluck<-:
pluck(x, 2, 2, "elt") <- "quuux"
x
# This is a shortcut for the prefix function assign_in():
y <- assign_in(x, list(2, 2, "elt"), value = "QUUUX")
y
# pluck() also supports accessor functions:
my_element <- function(x) x[[2]]$elt
# The accessor can then be passed to pluck:
pluck(x, 1, my_element)
pluck(x, 2, my_element)
# Even for this simple data structure, this is more readable than
# the alternative form because it requires you to read both from
# right-to-left and from left-to-right in different parts of the
# expression:
my_element(x[[1]])
# If you have a list of accessors, you can splice those in with `!!!`:
idx <- list(1, my_element)
pluck(x, !!!idx)
}
\seealso{
\code{\link[=attr_getter]{attr_getter()}} for creating attribute getters suitable
for use with \code{pluck()} and \code{chuck()}. \code{\link[=modify_in]{modify_in()}} for
applying a function to a pluck location.
}
purrr/man/has_element.Rd 0000644 0001762 0000144 00000000631 13630736102 014753 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/detect.R
\name{has_element}
\alias{has_element}
\title{Does a list contain an object?}
\usage{
has_element(.x, .y)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.y}{Object to test for}
}
\description{
Does a list contain an object?
}
\examples{
x <- list(1:10, 5, 9.9)
x \%>\% has_element(1:10)
x \%>\% has_element(3)
}
purrr/man/compose.Rd 0000644 0001762 0000144 00000002217 13630736102 014136 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compose.R
\name{compose}
\alias{compose}
\title{Compose multiple functions}
\usage{
compose(..., .dir = c("backward", "forward"))
}
\arguments{
\item{...}{Functions to apply in order (from right to left by
default). Formulas are converted to functions in the usual way.
These dots support \link[rlang:list2]{tidy dots} features. In
particular, if your functions are stored in a list, you can
splice that in with \verb{!!!}.}
\item{.dir}{If \code{"backward"} (the default), the functions are called
in the reverse order, from right to left, as is conventional in
mathematics. If \code{"forward"}, they are called from left to right.}
}
\value{
A function
}
\description{
Compose multiple functions
}
\examples{
not_null <- compose(`!`, is.null)
not_null(4)
not_null(NULL)
add1 <- function(x) x + 1
compose(add1, add1)(8)
# You can use the formula shortcut for functions:
fn <- compose(~ paste(.x, "foo"), ~ paste(.x, "bar"))
fn("input")
# Lists of functions can be spliced with !!!
fns <- list(
function(x) paste(x, "foo"),
~ paste(.x, "bar")
)
fn <- compose(!!!fns)
fn("input")
}
purrr/man/lmap.Rd 0000644 0001762 0000144 00000010112 13630736102 013413 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lmap.R
\name{lmap}
\alias{lmap}
\alias{lmap_if}
\alias{lmap_at}
\title{Apply a function to list-elements of a list}
\usage{
lmap(.x, .f, ...)
lmap_if(.x, .p, .f, ..., .else = NULL)
lmap_at(.x, .at, .f, ...)
}
\arguments{
\item{.x}{A list or data frame.}
\item{.f}{A function that takes and returns a list or data frame.}
\item{...}{Additional arguments passed on to the mapped function.}
\item{.p}{A single predicate function, a formula describing such a
predicate function, or a logical vector of the same length as \code{.x}.
Alternatively, if the elements of \code{.x} are themselves lists of
objects, a string indicating the name of a logical element in the
inner lists. Only those elements where \code{.p} evaluates to
\code{TRUE} will be modified.}
\item{.else}{A function applied to elements of \code{.x} for which \code{.p}
returns \code{FALSE}.}
\item{.at}{A character vector of names, positive numeric vector of
positions to include, or a negative numeric vector of positions to
exlude. Only those elements corresponding to \code{.at} will be modified.
If the \code{tidyselect} package is installed, you can use \code{vars()} and
the \code{tidyselect} helpers to select elements.}
}
\value{
If \code{.x} is a list, a list. If \code{.x} is a data
frame, a data frame.
}
\description{
\code{lmap()}, \code{lmap_at()} and \code{lmap_if()} are similar to
\code{map()}, \code{map_at()} and \code{map_if()}, with the
difference that they operate exclusively on functions that take
\emph{and} return a list (or data frame). Thus, instead of mapping
the elements of a list (as in \code{.x[[i]]}), they apply a
function \code{.f} to each subset of size 1 of that list (as in
\code{.x[i]}). We call those elements \code{list-elements}).
}
\details{
Mapping the list-elements \code{.x[i]} has several advantages. It
makes it possible to work with functions that exclusively take a
list or data frame. It enables \code{.f} to access the attributes
of the encapsulating list, like the name of the components it
receives. It also enables \code{.f} to return a larger list than
the list-element of size 1 it got as input. Conversely, \code{.f}
can also return empty lists. In these cases, the output list is
reshaped with a different size than the input list \code{.x}.
}
\examples{
# Let's write a function that returns a larger list or an empty list
# depending on some condition. This function also uses the names
# metadata available in the attributes of the list-element
maybe_rep <- function(x) {
n <- rpois(1, 2)
out <- rep_len(x, n)
if (length(out) > 0) {
names(out) <- paste0(names(x), seq_len(n))
}
out
}
# The output size varies each time we map f()
x <- list(a = 1:4, b = letters[5:7], c = 8:9, d = letters[10])
x \%>\% lmap(maybe_rep)
# We can apply f() on a selected subset of x
x \%>\% lmap_at(c("a", "d"), maybe_rep)
# Or only where a condition is satisfied
x \%>\% lmap_if(is.character, maybe_rep)
# A more realistic example would be a function that takes discrete
# variables in a dataset and turns them into disjunctive tables, a
# form that is amenable to fitting some types of models.
# A disjunctive table contains only 0 and 1 but has as many columns
# as unique values in the original variable. Ideally, we want to
# combine the names of each level with the name of the discrete
# variable in order to identify them. Given these requirements, it
# makes sense to have a function that takes a data frame of size 1
# and returns a data frame of variable size.
disjoin <- function(x, sep = "_") {
name <- names(x)
x <- as.factor(x[[1]])
out <- lapply(levels(x), function(level) {
as.numeric(x == level)
})
names(out) <- paste(name, levels(x), sep = sep)
out
}
# Now, we are ready to map disjoin() on each categorical variable of a
# data frame:
iris \%>\% lmap_if(is.factor, disjoin)
mtcars \%>\% lmap_at(c("cyl", "vs", "am"), disjoin)
}
\seealso{
Other map variants:
\code{\link{imap}()},
\code{\link{invoke}()},
\code{\link{map2}()},
\code{\link{map_if}()},
\code{\link{map}()},
\code{\link{modify}()}
}
\concept{map variants}
purrr/man/safely.Rd 0000644 0001762 0000144 00000006116 13630741543 013763 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/output.R
\name{safely}
\alias{safely}
\alias{quietly}
\alias{possibly}
\alias{auto_browse}
\title{Capture side effects.}
\usage{
safely(.f, otherwise = NULL, quiet = TRUE)
quietly(.f)
possibly(.f, otherwise, quiet = TRUE)
auto_browse(.f)
}
\arguments{
\item{.f}{A function, formula, or vector (not necessarily atomic).
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function. There
are three ways to refer to the arguments:
\itemize{
\item For a single argument function, use \code{.}
\item For a two argument function, use \code{.x} and \code{.y}
\item For more arguments, use \code{..1}, \code{..2}, \code{..3} etc
}
This syntax allows you to create very compact anonymous functions.
If \strong{character vector}, \strong{numeric vector}, or \strong{list}, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of \code{.default} will be returned.}
\item{otherwise}{Default value to use when an error occurs.}
\item{quiet}{Hide errors (\code{TRUE}, the default), or display them
as they occur?}
}
\value{
\code{safely}: wrapped function instead returns a list with
components \code{result} and \code{error}. If an error occurred, \code{error} is
an \code{error} object and \code{result} has a default value (\code{otherwise}).
Else \code{error} is \code{NULL}.
\code{quietly}: wrapped function instead returns a list with components
\code{result}, \code{output}, \code{messages} and \code{warnings}.
\code{possibly}: wrapped function uses a default value (\code{otherwise})
whenever an error occurs.
}
\description{
These functions wrap functions so that instead of generating side effects
through printed output, messages, warnings, and errors, they return enhanced
output. They are all adverbs because they modify the action of a verb (a
function).
}
\details{
If you would like to include a function created with \code{safely}, \code{slowly}, or
\code{insistently} in a package, see \link{faq-adverbs-export}.
}
\examples{
safe_log <- safely(log)
safe_log(10)
safe_log("a")
list("a", 10, 100) \%>\%
map(safe_log) \%>\%
transpose()
# This is a bit easier to work with if you supply a default value
# of the same type and use the simplify argument to transpose():
safe_log <- safely(log, otherwise = NA_real_)
list("a", 10, 100) \%>\%
map(safe_log) \%>\%
transpose() \%>\%
simplify_all()
# To replace errors with a default value, use possibly().
list("a", 10, 100) \%>\%
map_dbl(possibly(log, NA_real_))
# For interactive usage, auto_browse() is useful because it automatically
# starts a browser() in the right place.
f <- function(x) {
y <- 20
if (x > 5) {
stop("!")
} else {
x
}
}
if (interactive()) {
map(1:6, auto_browse(f))
}
# It doesn't make sense to use auto_browse with primitive functions,
# because they are implemented in C so there's no useful environment
# for you to interact with.
}
purrr/man/map_if.Rd 0000644 0001762 0000144 00000010023 13630736102 013716 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/map.R
\name{map_if}
\alias{map_if}
\alias{map_at}
\alias{map_depth}
\title{Apply a function to each element of a vector conditionally}
\usage{
map_if(.x, .p, .f, ..., .else = NULL)
map_at(.x, .at, .f, ...)
map_depth(.x, .depth, .f, ..., .ragged = FALSE)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.p}{A single predicate function, a formula describing such a
predicate function, or a logical vector of the same length as \code{.x}.
Alternatively, if the elements of \code{.x} are themselves lists of
objects, a string indicating the name of a logical element in the
inner lists. Only those elements where \code{.p} evaluates to
\code{TRUE} will be modified.}
\item{.f}{A function, formula, or vector (not necessarily atomic).
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function. There
are three ways to refer to the arguments:
\itemize{
\item For a single argument function, use \code{.}
\item For a two argument function, use \code{.x} and \code{.y}
\item For more arguments, use \code{..1}, \code{..2}, \code{..3} etc
}
This syntax allows you to create very compact anonymous functions.
If \strong{character vector}, \strong{numeric vector}, or \strong{list}, it is
converted to an extractor function. Character vectors index by
name and numeric vectors index by position; use a list to index
by position and name at different levels. If a component is not
present, the value of \code{.default} will be returned.}
\item{...}{Additional arguments passed on to the mapped function.}
\item{.else}{A function applied to elements of \code{.x} for which \code{.p}
returns \code{FALSE}.}
\item{.at}{A character vector of names, positive numeric vector of
positions to include, or a negative numeric vector of positions to
exlude. Only those elements corresponding to \code{.at} will be modified.
If the \code{tidyselect} package is installed, you can use \code{vars()} and
the \code{tidyselect} helpers to select elements.}
\item{.depth}{Level of \code{.x} to map on. Use a negative value to
count up from the lowest level of the list.
\itemize{
\item \code{map_depth(x, 0, fun)} is equivalent to \code{fun(x)}.
\item \code{map_depth(x, 1, fun)} is equivalent to \code{x <- map(x, fun)}
\item \code{map_depth(x, 2, fun)} is equivalent to \code{x <- map(x, ~ map(., fun))}
}}
\item{.ragged}{If \code{TRUE}, will apply to leaves, even if they're not
at depth \code{.depth}. If \code{FALSE}, will throw an error if there are
no elements at depth \code{.depth}.}
}
\description{
The functions \code{map_if()} and \code{map_at()} take \code{.x} as input, apply
the function \code{.f} to some of the elements of \code{.x}, and return a
list of the same length as the input.
\itemize{
\item \code{map_if()} takes a predicate function \code{.p} as input to determine
which elements of \code{.x} are transformed with \code{.f}.
\item \code{map_at()} takes a vector of names or positions \code{.at} to specify
which elements of \code{.x} are transformed with \code{.f}.
}
\itemize{
\item \code{map_depth()} allows to apply \code{.f} to a specific
depth level of a nested vector.
}
}
\examples{
# Use a predicate function to decide whether to map a function:
map_if(iris, is.factor, as.character)
# Specify an alternative with the `.else` argument:
map_if(iris, is.factor, as.character, .else = as.integer)
# Use numeric vector of positions select elements to change:
iris \%>\% map_at(c(4, 5), is.numeric)
# Use vector of names to specify which elements to change:
iris \%>\% map_at("Species", toupper)
# Use `map_depth()` to recursively traverse nested vectors and map
# a function at a certain depth:
x <- list(a = list(foo = 1:2, bar = 3:4), b = list(baz = 5:6))
str(x)
map_depth(x, 2, paste, collapse = "/")
# Equivalent to:
map(x, map, paste, collapse = "/")
}
\seealso{
Other map variants:
\code{\link{imap}()},
\code{\link{invoke}()},
\code{\link{lmap}()},
\code{\link{map2}()},
\code{\link{map}()},
\code{\link{modify}()}
}
\concept{map variants}
purrr/man/reduce.Rd 0000644 0001762 0000144 00000011666 13646111347 013755 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reduce.R
\name{reduce}
\alias{reduce}
\alias{reduce2}
\title{Reduce a list to a single value by iteratively applying a binary function}
\usage{
reduce(.x, .f, ..., .init, .dir = c("forward", "backward"))
reduce2(.x, .y, .f, ..., .init)
}
\arguments{
\item{.x}{A list or atomic vector.}
\item{.f}{For \code{reduce()}, and \code{accumulate()}, a 2-argument
function. The function will be passed the accumulated value as
the first argument and the "next" value as the second argument.
For \code{reduce2()} and \code{accumulate2()}, a 3-argument function. The
function will be passed the accumulated value as the first
argument, the next value of \code{.x} as the second argument, and the
next value of \code{.y} as the third argument.
The reduction terminates early if \code{.f} returns a value wrapped in
a \code{\link[=done]{done()}}.}
\item{...}{Additional arguments passed on to the mapped function.}
\item{.init}{If supplied, will be used as the first value to start
the accumulation, rather than using \code{.x[[1]]}. This is useful if
you want to ensure that \code{reduce} returns a correct value when \code{.x}
is empty. If missing, and \code{.x} is empty, will throw an error.}
\item{.dir}{The direction of reduction as a string, one of
\code{"forward"} (the default) or \code{"backward"}. See the section about
direction below.}
\item{.y}{For \code{reduce2()} and \code{accumulate2()}, an additional
argument that is passed to \code{.f}. If \code{init} is not set, \code{.y}
should be 1 element shorter than \code{.x}.}
}
\description{
\code{reduce()} is an operation that combines the elements of a vector
into a single value. The combination is driven by \code{.f}, a binary
function that takes two values and returns a single value: reducing
\code{f} over \code{1:3} computes the value \code{f(f(1, 2), 3)}.
}
\section{Direction}{
When \code{.f} is an associative operation like \code{+} or \code{c()}, the
direction of reduction does not matter. For instance, reducing the
vector \code{1:3} with the binary function \code{+} computes the sum \code{((1 + 2) + 3)} from the left, and the same sum \code{(1 + (2 + 3))} from the
right.
In other cases, the direction has important consequences on the
reduced value. For instance, reducing a vector with \code{list()} from
the left produces a left-leaning nested list (or tree), while
reducing \code{list()} from the right produces a right-leaning list.
}
\section{Life cycle}{
\code{reduce_right()} is soft-deprecated as of purrr 0.3.0. Please use
the \code{.dir} argument of \code{reduce()} instead. Note that the algorithm
has changed. Whereas \code{reduce_right()} computed \code{f(f(3, 2), 1)},
\verb{reduce(.dir = \\"backward\\")} computes \code{f(1, f(2, 3))}. This is the
standard way of reducing from the right.
To update your code with the same reduction as \code{reduce_right()},
simply reverse your vector and use a left reduction:\if{html}{\out{
}}
\code{reduce2_right()} is soft-deprecated as of purrr 0.3.0 without
replacement. It is not clear what algorithmic properties should a
right reduction have in this case. Please reach out if you know
about a use case for a right reduction with a ternary function.
}
\examples{
# Reducing `+` computes the sum of a vector while reducing `*`
# computes the product:
1:3 \%>\% reduce(`+`)
1:10 \%>\% reduce(`*`)
# When the operation is associative, the direction of reduction
# does not matter:
reduce(1:4, `+`)
reduce(1:4, `+`, .dir = "backward")
# However with non-associative operations, the reduced value will
# be different as a function of the direction. For instance,
# `list()` will create left-leaning lists when reducing from the
# right, and right-leaning lists otherwise:
str(reduce(1:4, list))
str(reduce(1:4, list, .dir = "backward"))
# reduce2() takes a ternary function and a second vector that is
# one element smaller than the first vector:
paste2 <- function(x, y, sep = ".") paste(x, y, sep = sep)
letters[1:4] \%>\% reduce(paste2)
letters[1:4] \%>\% reduce2(c("-", ".", "-"), paste2)
x <- list(c(0, 1), c(2, 3), c(4, 5))
y <- list(c(6, 7), c(8, 9))
reduce2(x, y, paste)
# You can shortcircuit a reduction and terminate it early by
# returning a value wrapped in a done(). In the following example
# we return early if the result-so-far, which is passed on the LHS,
# meets a condition:
paste3 <- function(out, input, sep = ".") {
if (nchar(out) > 4) {
return(done(out))
}
paste(out, input, sep = sep)
}
letters \%>\% reduce(paste3)
# Here the early return branch checks the incoming inputs passed on
# the RHS:
paste4 <- function(out, input, sep = ".") {
if (input == "j") {
return(done(out))
}
paste(out, input, sep = sep)
}
letters \%>\% reduce(paste4)
}
\seealso{
\code{\link[=accumulate]{accumulate()}} for a version that returns all intermediate
values of the reduction.
}
purrr/man/partial.Rd 0000644 0001762 0000144 00000005140 13630736102 014123 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/partial.R
\name{partial}
\alias{partial}
\title{Partial apply a function, filling in some arguments.}
\usage{
partial(.f, ..., .env = NULL, .lazy = NULL, .first = NULL)
}
\arguments{
\item{.f}{a function. For the output source to read well, this should be a
named function.}
\item{...}{named arguments to \code{.f} that should be partially applied.
Pass an empty \verb{... = } argument to specify the position of future
arguments relative to partialised ones. See
\code{\link[rlang:call_modify]{rlang::call_modify()}} to learn more about this syntax.
These dots support quasiquotation and quosures. If you unquote a
value, it is evaluated only once at function creation time.
Otherwise, it is evaluated each time the function is called.}
\item{.env}{Soft-deprecated as of purrr 0.3.0. The environments are
now captured via quosures.}
\item{.lazy}{Soft-deprecated as of purrr 0.3.0. Please unquote the
arguments that should be evaluated once at function creation time.}
\item{.first}{Soft-deprecated as of purrr 0.3.0. Please pass an
empty argument \verb{... = } to specify the position of future
arguments.}
}
\description{
Partial function application allows you to modify a function by pre-filling
some of the arguments. It is particularly useful in conjunction with
functionals and other function operators.
Note that an argument can only be partialised once.
}
\examples{
# Partial is designed to replace the use of anonymous functions for
# filling in function arguments. Instead of:
compact1 <- function(x) discard(x, is.null)
# we can write:
compact2 <- partial(discard, .p = is.null)
# partial() works fine with functions that do non-standard
# evaluation
my_long_variable <- 1:10
plot2 <- partial(plot, my_long_variable)
plot2()
plot2(runif(10), type = "l")
# Note that you currently can't partialise arguments multiple times:
my_mean <- partial(mean, na.rm = TRUE)
my_mean <- partial(my_mean, na.rm = FALSE)
try(my_mean(1:10))
# The evaluation of arguments normally occurs "lazily". Concretely,
# this means that arguments are repeatedly evaluated across invocations:
f <- partial(runif, n = rpois(1, 5))
f
f()
f()
# You can unquote an argument to fix it to a particular value.
# Unquoted arguments are evaluated only once when the function is created:
f <- partial(runif, n = !!rpois(1, 5))
f
f()
f()
# By default, partialised arguments are passed before new ones:
my_list <- partial(list, 1, 2)
my_list("foo")
# Control the position of these arguments by passing an empty
# `... = ` argument:
my_list <- partial(list, 1, ... = , 2)
my_list("foo")
}
purrr/man/set_names.Rd 0000644 0001762 0000144 00000000541 13630736102 014445 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reexport-rlang.R
\docType{import}
\name{set_names}
\alias{set_names}
\title{Set names in a vector}
\description{
These objects are imported from other packages. Follow the links
below to see their documentation.
\describe{
\item{rlang}{\code{\link[rlang]{set_names}}}
}}
purrr/man/null-default.Rd 0000644 0001762 0000144 00000000573 13630736102 015070 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reexport-rlang.R
\docType{import}
\name{null-default}
\alias{null-default}
\alias{\%||\%}
\title{Default value for \code{NULL}}
\description{
These objects are imported from other packages. Follow the links
below to see their documentation.
\describe{
\item{rlang}{\code{\link[rlang]{\%||\%}}}
}}
purrr/man/insistently.Rd 0000644 0001762 0000144 00000005754 13630741543 015074 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rate.R
\name{insistently}
\alias{insistently}
\alias{slowly}
\title{Transform a function to make it run insistently or slowly}
\usage{
insistently(f, rate = rate_backoff(), quiet = TRUE)
slowly(f, rate = rate_delay(), quiet = TRUE)
}
\arguments{
\item{f}{A function to modify.}
\item{rate}{A \link[=rate_backoff]{rate} object determining the waiting time.}
\item{quiet}{If \code{FALSE}, prints a message displaying how long until
the next request.}
}
\description{
\itemize{
\item \code{insistently()} takes a function and modifies it to retry a given
amount of time on error.
\item \code{slowly()} takes a function and modifies it to wait a given
amount of time between each call.
}
The number and rate of attempts is determined by a
\link[=rate-helpers]{rate} object (by default a jittered exponential
backoff rate for \code{insistently()}, and a constant rate for
\code{slowly()}).
If you would like to include a function created with \code{safely}, \code{slowly}, or
\code{insistently} in a package, see \link{faq-adverbs-export}.
}
\examples{
# For the purpose of this example, we first create a custom rate
# object with a low waiting time between attempts:
rate <- rate_delay(0.1)
# slowly() causes a function to sleep for a given time between calls:
slow_runif <- slowly(~ runif(1), rate = rate, quiet = FALSE)
map(1:5, slow_runif)
# insistently() makes a function repeatedly try to work
risky_runif <- function(lo = 0, hi = 1) {
y <- runif(1, lo, hi)
if(y < 0.9) {
stop(y, " is too small")
}
y
}
# Let's now create an exponential backoff rate with a low waiting
# time between attempts:
rate <- rate_backoff(pause_base = 0.1, pause_min = 0.005, max_times = 4)
# Modify your function to run insistently.
insistent_risky_runif <- insistently(risky_runif, rate, quiet = FALSE)
set.seed(6) # Succeeding seed
insistent_risky_runif()
set.seed(3) # Failing seed
try(insistent_risky_runif())
# You can also use other types of rate settings, like a delay rate
# that waits for a fixed amount of time. Be aware that a delay rate
# has an infinite amount of attempts by default:
rate <- rate_delay(0.2, max_times = 3)
insistent_risky_runif <- insistently(risky_runif, rate = rate, quiet = FALSE)
try(insistent_risky_runif())
# insistently() and possibly() are a useful combination
rate <- rate_backoff(pause_base = 0.1, pause_min = 0.005)
possibly_insistent_risky_runif <- possibly(insistent_risky_runif, otherwise = -99)
set.seed(6)
possibly_insistent_risky_runif()
set.seed(3)
possibly_insistent_risky_runif()
}
\seealso{
\code{\link[httr:RETRY]{httr::RETRY()}} is a special case of \code{\link[=insistently]{insistently()}} for
HTTP verbs. \code{\link[=rate_backoff]{rate_backoff()}} and \code{\link[=rate_delay]{rate_delay()}} for creating
custom backoff rates. \code{\link[=rate_sleep]{rate_sleep()}} for the function powering
\code{insistently()} and \code{slowly()}. \code{\link[=safely]{safely()}} for another useful
function operator.
}
purrr/man/attr_getter.Rd 0000644 0001762 0000144 00000002124 13630736102 015012 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pluck.R
\name{attr_getter}
\alias{attr_getter}
\title{Create an attribute getter function}
\usage{
attr_getter(attr)
}
\arguments{
\item{attr}{An attribute name as string.}
}
\description{
\code{attr_getter()} generates an attribute accessor function; i.e., it
generates a function for extracting an attribute with a given
name. Unlike the base R \code{attr()} function with default options, it
doesn't use partial matching.
}
\examples{
# attr_getter() takes an attribute name and returns a function to
# access the attribute:
get_rownames <- attr_getter("row.names")
get_rownames(mtcars)
# These getter functions are handy in conjunction with pluck() for
# extracting deeply into a data structure. Here we'll first
# extract by position, then by attribute:
obj1 <- structure("obj", obj_attr = "foo")
obj2 <- structure("obj", obj_attr = "bar")
x <- list(obj1, obj2)
pluck(x, 1, attr_getter("obj_attr")) # From first object
pluck(x, 2, attr_getter("obj_attr")) # From second object
}
\seealso{
\code{\link[=pluck]{pluck()}}
}
purrr/man/figures/ 0000755 0001762 0000144 00000000000 13630736102 013644 5 ustar ligges users purrr/man/figures/lifecycle-defunct.svg 0000644 0001762 0000144 00000001704 13630736102 017754 0 ustar ligges users