Skip to content

Commit 76cd705

Browse files
committed
cran check
1 parent 1496348 commit 76cd705

16 files changed

Lines changed: 207 additions & 6 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
^LICENSE\.md$
66
^CITATION\.cff$
77
^RELEASING\.md$
8+
^cran-comments\.md$
89
^emissions\.csv$

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ authors:
88
type: software
99
license: MIT
1010
repository-code: "https://github.com/beabock/CodeCarbonR"
11-
version: 0.0.0.9000
12-
date-released: "2026-08-04"
11+
version: 0.1.0
12+
date-released: "2026-08-19"
1313
# Once tagged and archived on Zenodo, add the minted DOI here, e.g.:
1414
# doi: 10.5281/zenodo.XXXXXXX
1515
# and Zenodo's concept DOI (the one that always resolves to the latest

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: CodeCarbonR
22
Title: Track Energy Consumption and Carbon Emissions of R Code
3-
Version: 0.0.0.9000
3+
Version: 0.1.0
44
Authors@R:
5-
person("Beatrice", "Bock", email = "beabockm@gmail.com", role = c("aut", "cre"))
5+
person("Beatrice", "Bock", email = "beabockm@gmail.com", role = c("aut", "cre", "cph"))
66
Description: Wraps the Python 'codecarbon' package via 'reticulate' to
77
measure the energy consumption and estimated carbon emissions of R
88
code. Provides a self-contained setup routine that installs

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CodeCarbonR 0.0.0.9000
1+
# CodeCarbonR 0.1.0
22

33
## New features
44

R/countries.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
#' [with_emissions_tracked()] must be one of the codes returned here.
66
#'
77
#' @return A data frame with `iso_code` and `country_name` columns.
8+
#' @examples
9+
#' \donttest{
10+
#' # Requires codecarbon to be installed (setup_carbon_tracker()); not run
11+
#' # on CRAN's check machines, which don't have it.
12+
#' if (carbon_tracker_ready()) {
13+
#' countries <- list_carbon_tracker_countries()
14+
#' head(countries)
15+
#' }
16+
#' }
817
#' @export
918
list_carbon_tracker_countries <- function() {
1019
ensure_codecarbon_available()

R/setup.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#' @param force Reinstall codecarbon even if it's already available.
2222
#' @return Invisibly, `TRUE` if codecarbon is ready to use after the call,
2323
#' `FALSE` if setup was cancelled.
24+
#' @examples
25+
#' \dontrun{
26+
#' # Installs software and prompts for confirmation, so this never runs
27+
#' # under R CMD check (or any other non-interactive session) -- call it
28+
#' # once, by hand, from an interactive R console.
29+
#' setup_carbon_tracker()
30+
#' }
2431
#' @export
2532
setup_carbon_tracker <- function(force = FALSE) {
2633
if (!force && carbon_tracker_ready()) {
@@ -68,6 +75,8 @@ setup_carbon_tracker <- function(force = FALSE) {
6875
#'
6976
#' @return `TRUE` if codecarbon can be imported, `FALSE` otherwise (including
7077
#' when no Python interpreter can be found at all).
78+
#' @examples
79+
#' carbon_tracker_ready()
7180
#' @export
7281
carbon_tracker_ready <- function() {
7382
tryCatch(reticulate::py_module_available("codecarbon"), error = function(e) FALSE)

R/tracker.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ CarbonTracker <- R6::R6Class(
6767
#' @param ... Passed to `codecarbon.OfflineEmissionsTracker`, e.g.
6868
#' `measure_power_secs`, `output_dir`, `log_level`.
6969
#' @return A `CarbonTracker` R6 object.
70+
#' @examples
71+
#' \donttest{
72+
#' # Requires codecarbon to be installed (setup_carbon_tracker()); not run
73+
#' # on CRAN's check machines, which don't have it.
74+
#' if (carbon_tracker_ready()) {
75+
#' tracker <- carbon_tracker(country_iso_code = "USA", output_dir = tempdir())
76+
#' tracker$start()
77+
#' Sys.sleep(1)
78+
#' emissions <- tracker$stop()
79+
#' print(emissions)
80+
#' }
81+
#' }
7082
#' @export
7183
carbon_tracker <- function(country_iso_code = NULL, project_name = "CodeCarbonR", ...) {
7284
CarbonTracker$new(country_iso_code = country_iso_code, project_name = project_name, ...)

R/with-emissions-tracked.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
#' @param ... Passed to [carbon_tracker()].
88
#' @return A `carbon_emissions_result`: `$result` holds the value of `expr`,
99
#' `$emissions` holds the `carbon_emissions` object.
10+
#' @examples
11+
#' \donttest{
12+
#' # Requires codecarbon to be installed (setup_carbon_tracker()); not run
13+
#' # on CRAN's check machines, which don't have it.
14+
#' if (carbon_tracker_ready()) {
15+
#' out <- with_emissions_tracked(
16+
#' Sys.sleep(1),
17+
#' country_iso_code = "USA",
18+
#' output_dir = tempdir()
19+
#' )
20+
#' print(out)
21+
#' }
22+
#' }
1023
#' @export
1124
with_emissions_tracked <- function(expr, country_iso_code = NULL, ...) {
1225
tracker <- carbon_tracker(country_iso_code = country_iso_code, ...)

RELEASING.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,69 @@ guarantees on top. Frictions specific to this package:
124124
explaining that `codecarbon` has no R equivalent and that setup is
125125
opt-in, confirmed, and isolated to its own conda environment rather
126126
than touching the user's system Python.
127+
128+
### 4a. Step-by-step, once you decide to go for it
129+
130+
Pre-submission (in addition to the package-specific fixes above):
131+
132+
- [ ] Every exported function (`setup_carbon_tracker()`, `carbon_tracker()`,
133+
`with_emissions_tracked()`, `list_carbon_tracker_countries()`,
134+
`carbon_tracker_ready()`) needs an `@examples` block in its roxygen
135+
comment. None currently exist. Wrap any example that would call
136+
`setup_carbon_tracker()`, start a tracker, or otherwise touch
137+
Python/network in `\donttest{}` (runs on your machine, skipped on
138+
CRAN's checks) -- e.g. show `list_carbon_tracker_countries()` or
139+
`carbon_tracker_ready()` unwrapped since those don't touch Python,
140+
but wrap a `with_emissions_tracked()` example in `\donttest{}`.
141+
- [ ] Confirm `Authors@R` includes a copyright holder role -- add `"cph"`
142+
to Beatrice Bock's `role = c(...)` in `DESCRIPTION` if it's only
143+
`c("aut", "cre")` currently (CRAN wants an explicit copyright holder,
144+
not just author/maintainer).
145+
- [ ] Write `cran-comments.md` at the repo root (`.Rbuildignore` it if you
146+
don't want it in the built tarball, though CRAN's web form also asks
147+
for these comments directly). Cover: this is a first submission;
148+
what the package does in one line; and the Python/conda point noted
149+
above -- `codecarbon` has no R equivalent, `setup_carbon_tracker()`
150+
is opt-in/interactive/confirmed and installs into its own isolated
151+
conda environment, never touches the user's system Python, and
152+
never runs during `R CMD check` (it errors intentionally in
153+
non-interactive contexts, which is what the test suite checks for).
154+
- [ ] From R, in the package directory:
155+
```r
156+
usethis::use_version("minor") # bumps 0.0.0.9000 -> 0.1.0, tags NEWS.md
157+
devtools::check(remote = TRUE, manual = TRUE) # full local check
158+
devtools::check_win_devel() # builds on R's Windows dev servers, emails you the log
159+
urlchecker::url_check() # catches dead links in docs/README/vignette
160+
```
161+
All three should come back clean (0 errors, 0 warnings, ideally 0
162+
notes) before submitting. `check_win_devel()` in particular catches
163+
things your local machine's R version won't.
164+
- [ ] Update `NEWS.md`'s heading from `# CodeCarbonR (development version)`
165+
(or `0.0.0.9000`) to the real version, and `CITATION.cff`'s
166+
`version:`/`date-released:` to match.
167+
168+
Submission:
169+
170+
- [ ] `devtools::submit_cran()` -- builds the source tarball, uploads it
171+
to CRAN's submission form, and pulls maintainer info + your
172+
`cran-comments.md` content into the form automatically. (Manual
173+
alternative: build with `R CMD build .`, then upload the resulting
174+
`.tar.gz` yourself at
175+
[cran.r-project.org/submit.html](https://cran.r-project.org/submit.html).)
176+
- [ ] **(you)** CRAN emails a confirmation link to the maintainer address
177+
in `DESCRIPTION` -- click it. The submission doesn't enter the queue
178+
until confirmed.
179+
- [ ] Wait. CRAN's automated checks (multiple OSes/R versions) typically
180+
report back within a day or two; a human CRAN team member reviews
181+
after that. Total time is unpredictable -- same-day acceptances and
182+
multi-week back-and-forth both happen, and a package installing
183+
external software during setup (even opt-in) is exactly the kind of
184+
thing that can prompt a question rather than an immediate accept.
185+
- [ ] If CRAN comes back with required changes: fix them, bump the patch
186+
version again (e.g. `0.1.0` -> `0.1.1`), add a line to
187+
`cran-comments.md` under a "Resubmission" heading explaining what
188+
changed, and resubmit the same way.
189+
- [ ] On acceptance: tag/release on GitHub if you haven't already (Section
190+
2 above), then bump `DESCRIPTION`'s version to a new `.9000`
191+
development suffix (e.g. `0.1.0.9000`) so it's clear `main` is past
192+
the released version.

cran-comments.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# CRAN comments
2+
3+
## Submission
4+
5+
This is the first submission of CodeCarbonR to CRAN.
6+
7+
CodeCarbonR wraps the Python `codecarbon` package (via `reticulate`) to
8+
measure the energy consumption and estimated carbon emissions of R code.
9+
There is no R-native equivalent of `codecarbon`, which is why this package
10+
depends on a Python backend rather than reimplementing emissions tracking
11+
natively.
12+
13+
## Notes on Python/conda dependency
14+
15+
* `setup_carbon_tracker()` is the only function that installs software. It
16+
is opt-in (never called automatically), requires explicit user
17+
confirmation via `utils::menu()`, and installs `codecarbon` into its own
18+
dedicated conda environment (`r-codecarbon`) rather than touching the
19+
user's system Python or any existing R/Python installation.
20+
* `setup_carbon_tracker()` refuses to run in a non-interactive session
21+
(`stop()`s immediately if `!interactive()`), so it never runs during
22+
`R CMD check`, and this refusal is itself covered by a test
23+
(`tests/testthat/test-setup.R`).
24+
* No example, test, or vignette installs software, writes outside
25+
`tempdir()`, or requires network access during `R CMD check`.
26+
Examples and tests that would otherwise touch Python/codecarbon are
27+
wrapped in `\donttest{}`/`\dontrun{}` or guarded with
28+
`testthat::skip_on_cran()` plus a runtime `carbon_tracker_ready()`
29+
check, so they no-op cleanly on CRAN's check machines (which will not
30+
have codecarbon installed).
31+
* `vignettes/quickstart.Rmd` uses `eval = FALSE` on every chunk and shows
32+
realistic example output as literal text, so building it never touches
33+
Python or the network.
34+
35+
## R CMD check results
36+
37+
0 errors | 0 warnings | 0 notes (checked with `R CMD check --as-cran` on
38+
Windows; see `RELEASING.md` for details of this package's release
39+
process).
40+
41+
## Downstream dependencies
42+
43+
This is a new package; there are no reverse dependencies.

0 commit comments

Comments
 (0)