Skip to content

Commit 2cbf0b7

Browse files
author
hornik
committed
Document and export analyze_license().
git-svn-id: https://svn.r-project.org/R/trunk@87983 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent c09a731 commit 2cbf0b7

File tree

4 files changed

+295
-9
lines changed

4 files changed

+295
-9
lines changed

src/library/base/R/namespace.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ loadNamespace <- function (package, lib.loc = NULL,
431431
## moved from library() in R 3.4.0
432432
checkLicense <- function(pkg, pkgInfo, pkgPath)
433433
{
434-
L <- tools:::analyze_license(pkgInfo$DESCRIPTION["License"])
434+
L <- tools::analyze_license(pkgInfo$DESCRIPTION["License"])
435435
if(!L$is_empty && !L$is_verified) {
436436
site_file <-
437437
path.expand(file.path(R.home("etc"), "licensed.site"))

src/library/tools/NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export("check_package_urls",
7171

7272
export("R")
7373

74+
export("analyze_license")
75+
7476
exportPattern("^SIG.+")
7577

7678
S3method("[", "check_details_changes")

src/library/tools/man/licensetools.Rd

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
% File src/library/tools/man/licensetools.Rd
2+
% Part of the R package, https://www.R-project.org
3+
% Copyright 2025 R Core Team
4+
% Distributed under GPL 2 or later
5+
6+
\name{licensetools}
7+
\alias{analyze_license}
8+
\title{License Tools}
9+
\description{
10+
Tools for computing on license specifications.
11+
}
12+
\usage{
13+
analyze_license(x)
14+
}
15+
\arguments{
16+
\item{x}{a character string.}
17+
}
18+
\details{
19+
R packages use the \samp{License} field in their \file{DESCRIPTION}
20+
file to specify their license in a standardized form described in
21+
section \sQuote{Licenses} of the \sQuote{Writing R Extensions} manual.
22+
This uses alternatives of individual specifications
23+
(\sQuote{components}) which can use version restrictions or give
24+
pointers to \file{LICENSE} (or \file{LICENCE}) files either
25+
restricting the base license or giving a full license.
26+
27+
Function \code{analyze_license()} checks if a given character string
28+
provides such a standardized license spec (or something recognized as
29+
a historic exception which can be transformed to a standardized spec).
30+
If standardizable, it extracts the individual components and where
31+
these give version ranges the corresponding expansions into components
32+
with fixed versions. It also indicates whether the license can be
33+
verified to be FOSS
34+
(\url{https://en.wikipedia.org/wiki/Free_and_open-source_software})
35+
licenses.
36+
}
37+
\value{
38+
a list with elements including
39+
\item{is_canonical}{a logical indicating whether the given string
40+
is a standardized license spec.}
41+
\item{is_standardizable}{a logical indicating whether the given string
42+
is a standardized license spec, or can be transformed to one.}
43+
\item{standardization}{a character string giving the standardized
44+
license spec correponding to the given string if this is
45+
standardizable.}
46+
\item{components}{the components of the standardized license spec.}
47+
\item{expansions}{the expansions of the components of the standardized
48+
license spec.}
49+
\item{is_verified}{a logical indicating whether the given string can
50+
be verified to specify a FOSS license.}
51+
}
52+
\examples{
53+
## Examples from section 'Licenses' of 'Writing R Extensions':
54+
analyze_license("GPL-2")
55+
analyze_license("LGPL (>= 2.0, < 3) | Mozilla Public License")
56+
analyze_license("GPL-2 | file LICENCE")
57+
analyze_license("GPL (>= 2) | BSD_3_clause + file LICENSE")
58+
analyze_license("Artistic-2.0 | AGPL-3 + file LICENSE")
59+
}

tests/Examples/tools-Ex.Rout.save

+233-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
R Under development (unstable) (2024-09-20 r87182) -- "Unsuffered Consequences"
3-
Copyright (C) 2024 The R Foundation for Statistical Computing
2+
R Under development (unstable) (2025-03-15 r87978) -- "Unsuffered Consequences"
3+
Copyright (C) 2025 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

66
R is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -96,8 +96,8 @@ $status
9696

9797
$stdout
9898
[1] ""
99-
[2] "R Under development (unstable) (2024-09-20 r87182) -- \"Unsuffered Consequences\""
100-
[3] "Copyright (C) 2024 The R Foundation for Statistical Computing"
99+
[2] "R Under development (unstable) (2025-03-15 r87978) -- \"Unsuffered Consequences\""
100+
[3] "Copyright (C) 2025 The R Foundation for Statistical Computing"
101101
[4] "Platform: x86_64-pc-linux-gnu"
102102
[5] ""
103103
[6] "R is free software and comes with ABSOLUTELY NO WARRANTY."
@@ -112,10 +112,10 @@ $stdout
112112
[15] "'help.start()' for an HTML browser interface to help."
113113
[16] "Type 'q()' to quit R."
114114
[17] ""
115-
[18] "> x <- readRDS(\"/tmp/RtmppU3jOk/runri1222936a0e6877\")"
115+
[18] "> x <- readRDS(\"/tmp/RtmpdMEyMD/runri27c6bb59ea22a0\")"
116116
[19] "> options(repos = x$repos)"
117117
[20] "> y <- tryCatch(list(do.call(x$fun, x$args, quote = TRUE)), error = identity)"
118-
[21] "> saveRDS(y, \"/tmp/RtmppU3jOk/runro1222932d23e62e\")"
118+
[21] "> saveRDS(y, \"/tmp/RtmpdMEyMD/runro27c6bb1ae7e9dc\")"
119119
[22] "> "
120120

121121
$stderr
@@ -280,7 +280,7 @@ Error in assertWarning(ff()) :
280280
> bibstyle("unsorted", sortKeys = function(refs) seq_along(refs),
281281
+ fmtPrefix = function(paper) paste0("[", paper$.index, "]"),
282282
+ .init = TRUE)
283-
<environment: 0x55a55e43e3c0>
283+
<environment: 0x55cb7849ff00>
284284
> print(refs, .bibstyle = "unsorted")
285285
[1] R Core Team (2013). _R: A Language and Environment for Statistical
286286
Computing_. R Foundation for Statistical Computing, Vienna, Austria.
@@ -723,6 +723,231 @@ attr(,"match.length")
723723
>
724724
> ### ** Examples
725725
>
726+
>
727+
>
728+
>
729+
> cleanEx()
730+
> nameEx("licensetools")
731+
> ### * licensetools
732+
>
733+
> flush(stderr()); flush(stdout())
734+
>
735+
> ### Name: licensetools
736+
> ### Title: License Tools
737+
> ### Aliases: analyze_license
738+
>
739+
> ### ** Examples
740+
>
741+
> ## Examples from section 'Licenses' of 'Writing R Extensions':
742+
> analyze_license("GPL-2")
743+
$is_empty
744+
[1] FALSE
745+
746+
$is_canonical
747+
[1] TRUE
748+
749+
$bad_components
750+
character(0)
751+
752+
$is_standardizable
753+
[1] TRUE
754+
755+
$is_verified
756+
[1] TRUE
757+
758+
$standardization
759+
[1] "GPL-2"
760+
761+
$components
762+
[1] "GPL-2"
763+
764+
$expansions
765+
$expansions[[1]]
766+
[1] "GPL-2"
767+
768+
769+
$extensions
770+
NULL
771+
772+
$pointers
773+
NULL
774+
775+
$is_FOSS
776+
[1] TRUE
777+
778+
$restricts_use
779+
[1] FALSE
780+
781+
> analyze_license("LGPL (>= 2.0, < 3) | Mozilla Public License")
782+
$is_empty
783+
[1] FALSE
784+
785+
$is_canonical
786+
[1] TRUE
787+
788+
$bad_components
789+
character(0)
790+
791+
$is_standardizable
792+
[1] TRUE
793+
794+
$is_verified
795+
[1] TRUE
796+
797+
$standardization
798+
[1] "LGPL (>= 2.0, < 3) | Mozilla Public License"
799+
800+
$components
801+
[1] "LGPL (>= 2.0, < 3)" "Mozilla Public License"
802+
803+
$expansions
804+
$expansions[[1]]
805+
[1] "LGPL-2" "LGPL-2.1"
806+
807+
$expansions[[2]]
808+
[1] "MPL version 1.0" "MPL version 1.1" "MPL version 2.0"
809+
810+
811+
$extensions
812+
NULL
813+
814+
$pointers
815+
NULL
816+
817+
$is_FOSS
818+
[1] TRUE
819+
820+
$restricts_use
821+
[1] FALSE
822+
823+
> analyze_license("GPL-2 | file LICENCE")
824+
$is_empty
825+
[1] FALSE
826+
827+
$is_canonical
828+
[1] TRUE
829+
830+
$bad_components
831+
character(0)
832+
833+
$is_standardizable
834+
[1] TRUE
835+
836+
$is_verified
837+
[1] TRUE
838+
839+
$standardization
840+
[1] "GPL-2 | file LICENCE"
841+
842+
$components
843+
[1] "GPL-2" "file LICENCE"
844+
845+
$expansions
846+
$expansions[[1]]
847+
[1] "GPL-2"
848+
849+
$expansions[[2]]
850+
[1] "file LICENCE"
851+
852+
853+
$extensions
854+
NULL
855+
856+
$pointers
857+
[1] "LICENCE"
858+
859+
$is_FOSS
860+
[1] TRUE
861+
862+
$restricts_use
863+
[1] FALSE
864+
865+
> analyze_license("GPL (>= 2) | BSD_3_clause + file LICENSE")
866+
$is_empty
867+
[1] FALSE
868+
869+
$is_canonical
870+
[1] TRUE
871+
872+
$bad_components
873+
character(0)
874+
875+
$is_standardizable
876+
[1] TRUE
877+
878+
$is_verified
879+
[1] TRUE
880+
881+
$standardization
882+
[1] "GPL (>= 2) | BSD_3_clause + file LICENSE"
883+
884+
$components
885+
[1] "GPL (>= 2)" "BSD_3_clause + file LICENSE"
886+
887+
$expansions
888+
$expansions[[1]]
889+
[1] "GPL-2" "GPL-3"
890+
891+
$expansions[[2]]
892+
[1] "BSD_3_clause + file LICENSE"
893+
894+
895+
$extensions
896+
components extensible
897+
1 BSD_3_clause + file LICENSE TRUE
898+
899+
$pointers
900+
[1] "LICENSE"
901+
902+
$is_FOSS
903+
[1] TRUE
904+
905+
$restricts_use
906+
[1] FALSE
907+
908+
> analyze_license("Artistic-2.0 | AGPL-3 + file LICENSE")
909+
$is_empty
910+
[1] FALSE
911+
912+
$is_canonical
913+
[1] TRUE
914+
915+
$bad_components
916+
character(0)
917+
918+
$is_standardizable
919+
[1] TRUE
920+
921+
$is_verified
922+
[1] TRUE
923+
924+
$standardization
925+
[1] "Artistic-2.0 | AGPL-3 + file LICENSE"
926+
927+
$components
928+
[1] "Artistic-2.0" "AGPL-3 + file LICENSE"
929+
930+
$expansions
931+
$expansions[[1]]
932+
[1] "Artistic-2.0"
933+
934+
$expansions[[2]]
935+
[1] "AGPL-3 + file LICENSE"
936+
937+
938+
$extensions
939+
components extensible
940+
1 AGPL-3 + file LICENSE TRUE
941+
942+
$pointers
943+
[1] "LICENSE"
944+
945+
$is_FOSS
946+
[1] TRUE
947+
948+
$restricts_use
949+
[1] FALSE
950+
726951
>
727952
>
728953
>
@@ -1353,7 +1578,7 @@ needs Deep Thought
13531578
> cleanEx()
13541579
> options(digits = 7L)
13551580
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
1356-
Time elapsed: 0.333 0.016 0.729 0.293 0.082
1581+
Time elapsed: 0.389 0 0.763 0.293 0.075
13571582
> grDevices::dev.off()
13581583
null device
13591584
1

0 commit comments

Comments
 (0)