R (programming language): Difference between revisions

Content deleted Content added
m Reverting possible vandalism by 154.115.204.4 to version by 207.91.254.122. Report False Positive? Thanks, ClueBot NG. (4413697) (Bot)
 
(17 intermediate revisions by 9 users not shown)
Line 1:
{{Short description|Programming language for statistics}}
{{About|the programming language|the eighteenth letter of the English alphabet|R|other uses|R (disambiguation)}}
{{Use dmy dates|date=June 2018}}
{{Infobox programming language
Line 30 ⟶ 29:
| file_ext = {{Unbulleted list|.r<ref>{{Cite web|title=R scripts|url=http://mercury.webster.edu/aleshunas/R_learning_infrastructure/R%20scripts.html|access-date=2021-07-17|website=mercury.webster.edu}}</ref>|.rdata|.rhistory|.rds|.rda<ref>{{Cite web|date=2017-06-09|title=R Data Format Family (.rdata, .rda)|url=https://www.loc.gov/preservation/digital/formats/fdd/fdd000470.shtml|access-date=2021-07-17|website=Loc.gov}}</ref>}}
}}
{{redirect-distinguish|R lang|Erlang}}
 
'''R''' is a [[programming language]] for [[statistical computing]] and [[Data and information visualization|data visualization]]. It has been widely adopted in the fields of [[data mining]], [[bioinformatics]], [[data analysis]], and [[data science]].<ref>{{Cite journal
Line 58:
 
== History ==
{{Multiple image |total_width = 250 | align = left
{{Gallery
|title header = Co-originators of the R language
|File: image1 = Ross Ihaka (5189180796).jpg
|width=160 | height=170 |noborder=yes
| caption1 = [[Ross Ihaka]]
|align=center
|File: image2 = Robert Gentleman on R Consortium.jpg
|footer=
| caption2 = [[Robert Gentleman (statistician)|Robert Gentleman]]
|File:Ross Ihaka (5189180796).jpg
|Ross Ihaka
|alt1=
|File:Robert Gentleman on R Consortium.jpg
|Robert Gentleman
|alt2=
}}
 
R was started by professors [[Ross Ihaka]] and [[Robert Gentleman (statistician)|Robert Gentleman]] as a programming language to teach introductory statistics at the [[University of Auckland]].<ref name="otago_pg12">{{Cite web
|last=Ihaka
Line 182 ⟶ 176:
 
== Community ==
[[File:RConsortiumLogo.webp|thumb|The R Consortium is one of the three main groups that support R]]
There are three main groups that help support R software development:
 
Line 189 ⟶ 184:
 
''[[The R Journal]]'' is an [[open access]], [[academic journal]] that features short to medium-length articles on the use and development of R. The journal includes articles on packages, programming tips, CRAN news, and foundation news.
[[File:UseR Logo.png|thumb|125x125px|UseR! conference is one place the R community can gather at]]
 
The R community hosts many conferences and in-person meetups.{{efn|Information about conferences and meetings is available in a community-maintained list on GitHub, {{URL|jumpingrivers.github.io/meetingsR/}}}} These groups include:
 
Line 195 ⟶ 190:
* Directions in Statistical Computing (DSC) ([https://www.r-project.org/conferences/ website])
* [[R-Ladies]]: an organization to promote [[gender diversity]] in the R community ([https://rladies.org website])
* SatRdays: R-focused conferences held on Saturdays ([https://satrdays.orggithub.io/ website])
* RData ConferenceScience & AI Conferences ([https://rstats.ai/ website])
* posit::conf (formerly known as rstudio::conf) ([https://www.posit.co/conference/ website])
On social media sites such as Twitter, the hashtag <code>#rstats</code> can be used to follow new developments in the R community.<ref>{{Cite book |last=Wickham |first=Hadley |url=https://r4ds.had.co.nz/introduction.html |title=1 Introduction {{!}} R for Data Science |last2=Grolemund |first2=Garrett |date=January 2017 |publisher=[[O'Reilly Media]] |year=2017 |isbn=978-1491910399 |edition=1st |language=en}}</ref>
 
== Examples ==
Line 319 ⟶ 314:
</syntaxhighlight>
 
AnotherAn alternative to nested functions is the use of intermediate objects, rather than the pipe operator:
 
<syntaxhighlight lang="rout">
Line 326 ⟶ 321:
> print(num_mtcars_subset)
[1] 11
</syntaxhighlight>While the pipe operator can produce code that is easier to read, itinfluential isR advisableprogrammers like [[Hadley Wickham]] suggest to chain together at most 10-15 lines of code using this operator, asand wellsaving as to chunk codethem into [[Taskobjects (projecthaving management)|sub-tasks]]meaningful thatnames areto savedavoid into[[Code objectsobfuscating|code having meaningful namesobfuscation]].<ref>{{Cite book |last=Wickham |first=Hadley |url=https://r4ds.hadley.nz/ |title=R for data science: import, tidy, transform, visualize, and model data |last2=Çetinkaya-Rundel |first2=Mine |last3=Grolemund |first3=Garrett |date=2023 |publisher=O'Reilly |isbn=978-1-4920-9740-2 |edition=2nd |___location=Beijing; Sebastopol, CA |chapter=4 Workflow: code style |oclc=on1390607935 |chapter-url=https://r4ds.hadley.nz/workflow-style.html}}</ref>
 
The following is an example having fewer than 10 lines, which some readers may find difficult to grasp in the absence of intermediate named steps:<syntaxhighlight lang="r" line="1">(\(x, n = 42, key = c(letters, LETTERS, " ", ":", ")"))
strsplit(x, "")[[1]] |>
(Vectorize(\(chr) which(chr == key) - 1))() |>
(`+`)(n) |>
(`%%`)(length(key)) |>
(\(i) key[i + 1])() |>
paste(collapse = "")
)("duvFkvFksnvEyLkHAErnqnoyr")</syntaxhighlight>The following is a version of the preceding code that is easier to read:<syntaxhighlight lang="r">
default_key <- c(letters, LETTERS, " ", ":", ")")
 
f <- function(x, n = 42, key = default_key) {
split_input <- strsplit(x, "")[[1]]
results <- (Vectorize(\(chr) which(chr == key) - 1))(split_input) |>
(`+`)(n) |>
(`%%`)(length(key)) |>
(\(i) key[i + 1])()
combined_results <- paste(results, collapse = "")
return(combined_results)
}
 
f("duvFkvFksnvEyLkHAErnqnoyr")
</syntaxhighlight>
 
=== Object-oriented programming ===
The R language has native support for [[object-oriented programming]]. There are two native [[Application framework|frameworks]], the so-called S3 and S4 systems. The former, being more informal, supports single dispatch on the first argument, and objects are assigned to a class simply by setting a "class" attribute in each object. The latter is a system like the [[CLOS|Common Lisp Object System (CLOS)]], with formal classes (also derived from [[S (programming language)#S4|S]]) and generic methods, which supports [[multiple dispatch]] and [[multiple inheritance]]<ref>{{cite web|url=https://stat.ethz.ch/R-manual/R-devel/library/base/html/UseMethod.html|title=Class Methods|access-date=2024-04-25}}</ref>
Line 758 ⟶ 729:
|2015-03-09
|Smooth Sidewalk
|<ref>{{Cite book |last=Schulz |first=Charles M. |title=Happiness is a warm puppy |date=2019 |publisher=Penguin Workshop |___location=New York : Penguin Workshop |isbn=978-1-5247-8995-4}}</ref>{{Page needed|date=April 2024}}
|<ref>{{Cite web |title=R 3.1.3 is released |url=https://stat.ethz.ch/pipermail/r-announce/2015/000582.html |access-date=2024-04-07 |website=stat.ethz.ch}}</ref>
|-
Line 919 ⟶ 890:
|s2cid=1989369}}</ref> written in [[C++]].
* [[Oracle Corporation|Oracle's]] [https://github.com/oracle/fastr FastR] built on [https://www.graalvm.org/ GraalVM].
* [[TIBCO Software|TIBCO]] Enterprise Runtime for R (TERR) to integrate with [[Spotfire]].<ref>Jackson, Joab (16 May 2013). [httphttps://www.pcworld.com/article/2038944/tibco-offers-free-r-to-the-enterprise.html TIBCO offers free R to the enterprise]. ''PC World''. Retrieved 20 July 2015.</ref> (The company also created [[S-PLUS|S-Plus]], an implementation of the S language.)
 
Microsoft R Open (MRO) was an R implementation. As of 30 June 2021, Microsoft began to phase out MRO in favor of the CRAN distribution.<ref>{{cite web