-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08b_pkg_functions.qmd
1240 lines (853 loc) · 33.9 KB
/
08b_pkg_functions.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Packaging functionality"
---
## R Package Structure
Used to share functionality with the R community
- Useful **conventions**
- Useful **software development tools**
- Easy **publishing** through GitHub
## R Package conventions:
- **metadata**: in the **`DESCRIPTION` file**
- **functions** in **`.R` scripts** in the **`R/` folder**
- **tests** in the **`tests/` folder**
- **Documentation:**
- *functions* using **Roxygen notation**
- *workflows* using **`.Rmd` documents** in the **`vignettes/`** folder
## Software Engineering approach
Following conventions allows us to **make use of automated tools** for:
- **Checking** and **testing code**
- **Producing documentation** for code and workflows
- **Publishing, distributing** and **citing** code
## Anatomy of an R package
Let's use [`pkgreviewr`](https://github.com/ropensci-org/pkgreviewr), a package I authored to help automate some aspects of the rOpenSci review process, as an example to examine some elements of what makes a package:
## `DESCRIPTION` file
Capture metadata around the package - Functionality description - Creators - License
```
Package: pkgreviewr
Type: Package
Title: rOpenSci package review project template
Version: 0.1.1
Authors@R: c(person("Anna", "Krystalli", email = "annakrystalli@googlemail.com",
role = c("aut", "cre")),
person("Maëlle", "Salmon", email = "maelle.salmon@yahoo.se", role = "aut"))
Description: Creates files and collects materials necessary to complete an rOpenSci package review.
Review files are prepopulated with review package specific metadata. Review package source code is
also cloned for local testing and inspection.
License: GPL-3 + file LICENSE
URL: https://github.com/ropenscilabs/pkgreviewr
BugReports: https://github.com/ropenscilabs/pkgreviewr/issues
Encoding: UTF-8
LazyData: true
Imports:
devtools,
git2r (>= 0.23.0),
usethis (>= 1.2.0),
here,
reprex,
gh,
base64enc,
whoami,
magrittr,
covr,
goodpractice,
assertthat,
httr,
rstudioapi,
clipr,
clisymbols,
crayon,
dplyr,
glue,
fs,
urltools,
shiny
Suggests:
testthat,
mockery,
knitr,
rmarkdown
RoxygenNote: 6.1.1
Remotes:
ropensci/git2r
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
```
### citation
```{r}
citation("pkgreviewr")
```
## Dependency management
It’s the job of the DESCRIPTION to **list the packages that your package needs to work**.
```
Imports:
devtools,
git2r (>= 0.23.0),
usethis (>= 1.2.0),
here,
reprex,
gh,
base64enc,
whoami,
magrittr,
covr,
goodpractice,
assertthat,
httr,
rstudioapi,
clipr,
clisymbols,
crayon,
dplyr,
glue,
fs,
urltools,
shiny
```
Imports are necessary dependencies for the functions in your package to work
```
Suggests:
testthat,
mockery,
knitr,
rmarkdown
```
Suggests are dependencies that are not necessary for the functions in your package but might be neccessary to run all the vignettes or tests in your package
## `R/`
- Keep all functions in R scripts in `R/` folder
```
.
├── github.R
├── pkgreview.R
├── pkgreviewr-package.R
├── render-templates.R
├── rmd-utils.R
├── style.R
└── utils.R
0 directories, 7 files
```
### example function script
Create a new function `.R` file in the `R/` folder
```{r, eval=FALSE}
library(usethis)
use_r("add")
```
```
R
└── add.R
0 directories, 1 files
```
## Document functions with `Roxygen`
- Document functions with **Roxygen** notation
- Automatically create help files on build
```{r}
#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of x and y.
#' @examples
#' add(1, 1)
#' add(10, 1)
add <- function(x, y) {
x + y
}
```
## `tests/`
Tests provide confidence in what the code is doing.
*Contents of `pkgreviewr` test folder*
```
.
├── testthat
│ ├── setup.R
│ ├── test-create-pkgreview.R
│ ├── test-gh-calls.R
│ ├── test-render-templates.R
│ └── test-setup.R
└── testthat.R
1 directory, 6 files
```
### Example test
```{r, eval=FALSE}
use_test("add")
```
```
tests
├── testthat
│ ├── test-add.R
└── testthat.R
```
```{r, eval=FALSE}
test_that("add works", {
expect_equal(add(2, 2), 4)
})
```
The **R package structure** can help with providing a logical organisation of files, by **providing a set of standard locations for certain types of files**.
To work with packages in RStudio we use the **Build pane**, which includes a variety of tools for **building, documenting and testing packages**. This will appear if Rstudio recognises the project as an R package.

# :computer: Create your first package
::: {.callout-tip collapse="true"}
## Creating a new package locally
To create a new package, you can follow the steps for creating any new project, but this time select **`R package`** instead of `New Project` and call your new package `mypackage`.
::: {.alert .alert-info}
<strong>File \> New Project... \> New Directory \> R package \> mypackage </strong>
:::
Otherwise, you can **use function `usethis::create_package("mypackage")`** to create a new package. The argument we provide is the path to here we want our new package created, the **last element being the package name**. Note that there are [restrictions on what characters can be used in a package name](https://r-pkgs.org/workflows101.html#naming).
:::
## Copy **`mypackage`** Project
To make things easier, I've gone ahead and **set up the basic contents of a new package in project `mypackage`.**
In our shared space click on the {{< fa plus-square >}} copy button next to the **mypackage** Project to copy it.

Your new project should have the following structure.
```
.
├── DESCRIPTION
├── NAMESPACE
├── R
└── project.Rproj
```
## Initialise git and commit files.
Let's **also configure git again, initialise our project as a git repository and commit our initial files**. We'll need to configure git again as this is a new Posit Cloud project.
```{r, eval=FALSE}
# configure git
usethis::use_git_config(
user.name = "Jane",
user.email = "jane@example.org"
)
# intialise git and commit
usethis::use_git()
```
```
✔ Setting active project to '/cloud/project/mypackage'
✔ Initialising Git repo
✔ Adding '.Rhistory', '.Rdata', '.httr-oauth', '.DS_Store', '.quarto' to '.gitignore'
There are 5 uncommitted files:
* '.gitignore'
* '.Rbuildignore'
* 'DESCRIPTION'
* 'mypackage.Rproj'
* 'NAMESPACE'
Is it ok to commit them?
1: No way
2: Nope
3: I agree
Selection: 3
✔ Adding files
✔ Making a commit with message 'Initial commit'
```
# :vertical_traffic_light: Functions in the **`R/`** dir
## Create function script and first function
Let's create a script and write our first function:
```{r, eval=FALSE}
usethis::use_r("hello")
```
```
• Modify 'R/hello.R'
```

In the opened `hello.R` script, let's write our first function:
```{r}
#| eval: false
hello <- function() {
print("Hello, world!")
}
```
It's a function that takes no arguments and prints `Hello, world!` to the console when called.
## Install package.
You can install a package locally from it's source code with function `devtools::install()`
```{r, eval=FALSE}
devtools::install()
```
```
── R CMD build ────────────────────────────────────────────
✔ checking for file ‘/cloud/project/mypackage/DESCRIPTION’ ...
─ preparing ‘mypackage’:
✔ checking DESCRIPTION meta-information
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘mypackage_0.0.0.9000.tar.gz’
Warning: invalid uid value replaced by that for user 'nobody'
Running /opt/R/4.3.3/lib/R/bin/R CMD INSTALL \
/tmp/RtmpVJXWXx/mypackage_0.0.0.9000.tar.gz \
--install-tests
* installing to library ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’
* installing *source* package ‘mypackage’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mypackage)
```
Or click on **{{< fa hammer >}} Install** on the Build panel

## Load library
You can now load it like any other package...
```{r, eval=FALSE}
library("mypackage")
```
## Try using function
Let's try using our function
```{r}
#| error: true
hello()
```
Oooops? Our function doesn't seem to be available! :thinking:
```{r}
#| echo: false
hello <- function() {
print("Hello, world!")
}
```
Let's try something else:
```{r}
#| eval: false
mypackage:::hello()
```
```{r}
#| echo: false
hello()
```
```{r, echo=FALSE}
rm(hello)
```
So what's happened here?
Although the package contains our function, **we have not exported it** to make it available to a user.
Currently **it is contained as an internal function**. Hence **we can access it with the notation for internal functions (`:::`)** but not directly when we load the package!
To export the function, **we will need to add a tag to tell R to do so** using a special documentation notation called **Roxygen**!
------------------------------------------------------------------------
# :vertical_traffic_light: Add Roxygen documentation
[`Roxygen2`](http://r-pkgs.had.co.nz/man.html) allows you to write specially-structured comments preceding each function definition to document:
- a description of what it does
- the inputs and outputs
- an example of how to use it
- **whether to export the function or treat it as internal**
These are **processed automatically to produce `.Rd` help files** for your functions and **control which functions are exported to the package `NAMESPACE`**.
Let's document our example function.
## Insert Roxygen skeleton
You can **insert a Roxygen skeleton** by placing the cursor within a function and clicking:
> **Code \> Insert Roxygen Skeleton**
```{r, eval=FALSE}
#' Title
#'
#' @return
#' @export
#'
#' @examples
hello <- function() {
print("Hello, world!")
}
```
## Roxygen basics
- `roxygen` notation indicated by **beginning line with `#'`**.
- **First line** will be the **title** for the function.
- After title, include a blank `#'` line and then write a **longer description.**
- `@param argument_name` **description of the argument.**
- `@return` description of **what the function returns.**
- `@export` tells `Roxygen2` to **add this function to the `NAMESPACE`** file, so that it will be **accessible to users.**
- `@examples` allows to include example of how to use a function
## Complete Roxygen documentation
```{r}
#' Hello World!
#'
#' Print hello greeting
#' @return prints hello greeting to console
#' @export
#'
#' @examples
#' hello()
hello <- function() {
print("Hello, world!")
}
```
## Autogenerate documentation
To auto-generate documentation:
- **use function `devtools::document()`** or
- click on **{{< fa cog >}} More > Document**

```
ℹ Updating mypackage documentation
ℹ Loading mypackage
Writing 'hello.Rd'
Writing 'NAMESPACE'
Documentation completed
```
This re-creates a `hello.Rd` help file in the `man/` folder and populates the `NAMESPACE` with our functions
::: callout-tip
### Configure Build Tools
We can also configure our Build Tools to **run `devtools::document()` every time we re-install the package**.
To do so, we click on the **Build \> Configure Build Tools > Generate documentation with Roxygen > [Configure...](){.btn .btn-outline-primary}** and then tick the **Install and Restart** box.

Now clicking {{< fa hammer >}} **Install** in the Build panel will also build your docs in the `man/` folder for you.
:::
Now that the documentation has been built, the help file for our `hello()` function is now available!

# :vertical_traffic_light: Personalise function
Let's go a step further and **customise our function so that the greeting is from ourselves!**
```{r, tidy="styler"}
#' Hello World!
#'
#' Print hello greeting
#' @return prints hello greeting to console from me
#' @export
#'
#' @examples
#' hello()
hello <- function() {
print("Hello, world from Anna")
}
```
## Add some fun!
Programming is most useful for having fun. So **let's make our function extra fun!**
We'll use package `cowsay`
```{r, eval=FALSE}
install.packages("cowsay")
```
which has a single function `say`, which does this...
```{r}
cowsay::say("Say whaaaaaat?", by = "shark")
```
:stuck_out_tongue_winking_eye:
So **let's create a function that randomly chooses one of the animals** available in `cowsay` **to deliver the greeting**, and also **allow the user to customise who the recipient of the greeting is**.
```{r}
#' Hello World!
#'
#' Print personalised hello greeting from me.
#'
#' @param name character string. Your name!
#'
#' @return prints hello greeting to console
#' @export
#'
#' @examples
#' hello()
#' hello("Lucy Elen")
hello <- function(name = NULL) {
# create greeting
if (is.null(name)){name <- "world"}
greeting <- paste("Hello", name, "from Anna!")
# randomly sample an animal
animal_names <- names(cowsay::animals)
i <- sample(1:length(animal_names), 1)
cowsay::say(greeting, animal_names[i])
}
```
Document, Install and restart to load our changes
```{r}
hello("y'all")
```
Let's **commit our current files and changes.**
# :vertical_traffic_light: Check package integrity
An **important part of the package development process is `R CMD check`**. `R CMD check` automatically **checks your code** and can **automatically detects many common problems** that we'd otherwise discover the hard way.
To check our package, we can:
- use `devtools::check()`
- press Ctrl/Cmd + Shift + E
- click on the :check:**Check** tab in the **Build** panel.
This:
- **Ensures that the documentation is up-to-date** by running `devtools::document()`.
- **Bundles the package** before checking it.
More info on [checks](http://r-pkgs.had.co.nz/check.html) here.
<br>
Both these run `R CMD check` which **return three types of messages**:
- **ERRORs**: Severe problems that you should fix regardless of whether or not you’re submitting to CRAN.
- **WARNINGs**: Likely problems that you must fix if you’re planning to submit to CRAN (and a good idea to look into even if you’re not).
- **NOTEs**: Mild problems. If you are submitting to CRAN, you should strive to eliminate all NOTEs, even if they are false positives.
Let's **Check** our package:
Click on the **Check** button (:clipboard: :white_check_mark:)
```
── R CMD check results ────────────────────────────── mypackage 0.0.0.9000 ────
Duration: 8.4s
❯ checking DESCRIPTION meta-information ... WARNING
Non-standard license specification:
What license is it under?
Standardizable: FALSE
❯ checking dependencies in R code ... WARNING
'::' or ':::' import not declared from: ‘cowsay’
0 errors ✔ | 2 warnings ✖ | 0 notes ✔
Error: R CMD check found WARNINGs
Execution halted
Exited with status 1.
```
Aha, so our checks have thrown up some warnings! First, it's telling us we haven't added a `LICENSE`. It's also telling us that we have a dependency (import) from package `cowsay` which we haven't documented in the `DESCRIPTION` file. `usethis` to the rescue!
## :vertical_traffic_light: Add dependencies
Add `cowsay` as a dependency.
```{r, eval=FALSE}
usethis::use_package("cowsay")
```
```
✔ Setting active project to '/cloud/project'
✔ Adding 'cowsay' to Imports field in DESCRIPTION
• Refer to functions with `cowsay::fun()`
```
## Add License
```{r, eval = FALSE}
usethis::use_mit_license("Anna Krystalli")
```
```
✔ Adding 'MIT + file LICENSE' to License
✔ Writing 'LICENSE'
✔ Writing 'LICENSE.md'
✔ Adding '^LICENSE\\.md$' to '.Rbuildignore'
```

Check again...All should be good!
```
── R CMD check results ─ mypackage 0.0.0.9000 ────
Duration: 8s
0 errors ✔ | 0 warnings ✔ | 0 notes ✔
R CMD check succeeded
```
#### {{< fa square-check >}} Let's commit our current files and changes.
------------------------------------------------------------------------
# :vertical_traffic_light: Add Test
**Testing is a vital part of package development**. It ensures that our code does what you want it to do.
Once you're set up with a testing framework, the workflow is simple:
1. Modify your code or tests.
2. Test your package with Ctrl/Cmd + Shift + T or `devtools::test()`.
3. Repeat until all tests pass.
## Create test file
To create a new test file (and the testing framework if required), use function `usethis::use_test()`. It's good practice to name the test files after the `.R` files containing the functions being tested.
```{r, eval=FALSE}
usethis::use_test("hello")
```
``` r
✔ Adding 'testthat' to Suggests field in DESCRIPTION
✔ Adding '3' to Config/testthat/edition
✔ Creating 'tests/testthat/'
✔ Writing 'tests/testthat.R'
✔ Writing 'tests/testthat/test-hello.R'
• Modify 'tests/testthat/test-hello.R'
```
This just created the following folders and files
```
tests
├── testthat
│ └── test-hello.R
└── testthat.R
1 directory, 2 files
```
It also added `testthat` to the suggested packages in the `DESCRIPTION` file.
```
Suggests:
testthat
```
That's because you don't need test that to run the functions in `mypackage`, but you do if you want to run the tests.
When the tests are run (either through running `devtools::test()`, clicking on **More \> Test Package** in the Build panel or `Cmd/Ctrl + Shift + T`), the code in each test script in directory `testthat` is run.
## **`test-hello.R`**
Let's load the library so we can explore the `testthat` testing framework
```{r, message=FALSE}
library(testthat)
```
```{r}
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
```
If the test doesn't pass it throws an error
```{r, error=TRUE}
test_that("multiplication works", {
expect_equal(2 * 2, 5)
})
```
## Write test
Let's **write a simple test to check that we are getting an expected output type**.
One way to **test the consistency of the output of a function**, especially one that may output messages, warnings etc, like ours does, is to **use `expect_snapshot()`**.
This function takes a snapshot of the output of a function and compares it to the snapshot the next time the test is run.
Now, because our functions has a random element to it (selecting a random animal), we need to **set the seed** to ensure that the output is consistent across runs.
So let'sr eplace the placeholder testing code and add a snapshot test each for:
- the function's default behaviour.
- the function's behaviour when a `name` is provided.
```{r}
#| eval: false
test_that("hello works", {
set.seed(1)
expect_snapshot(hello())
expect_snapshot(hello("Lucy Elen"))
})
```
Now let's test our package
```{r, eval=FALSE}
devtools::test()
```
The first time we run our tests, `testthat` will create a snapshot of the output of our function and warns us of that. The next time we run the tests, it will compare the output of the function to the snapshot and let us know if it has changed.
If you run your tests twice you should have success!
```
==> devtools::test()
ℹ Testing mypackage
✔ | F W S OK | Context
✔ | 2 | hello
══ Results ═══════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 2 ]
```
#### {{< fa square-check >}} Let's commit our current files and changes.
# :vertical_traffic_light: Create README
The final document you will need for your package is a `README`.
```{r, eval=FALSE}
usethis::use_readme_rmd()
```
```
✔ Setting active project to '/cloud/project'
✔ Writing 'README.Rmd'
✔ Adding '^README\\.Rmd$' to '.Rbuildignore'
• Modify 'README.Rmd'
• Update 'README.Rmd' to include installation instructions.
✔ Writing '.git/hooks/pre-commit'
```
`.Rmd` documents are the predecessors to Quarto documents and allow us to run R code in our GitHub README.
Because it's an `.Rmd` but GitHub can only display an `md` document as it's landing page, this is a **special `.Rmd` that renders to a markdown document rather than `html`**.
The function adds a check to `.git` to ensure you commit an up to date version on the `md` when you commit changes to the `.Rmd`.
Important elements of a README to include:
- **Installation instructions:** In our case we will be distributing our package via GitHub, so we will include instructions on how to install the package from GitHub using `remotes::install_github("<yourgithubusername>/mypackage")`.
- **Description:** A brief description of what the package does.
- **Examples:** A few simple examples of how to use the package.
Complete the README. Here's what mine looks like:
````
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# mypackage
<!-- badges: start -->
<!-- badges: end -->
The goal of mypackage is to print a personalised greeting from me!
## Installation
You can install the development version of mypackage from GitHub with:
``` r
# install.packages("remotes")
remotes::install_github("annakrystalli/mypackage")
```
## Example
This is a basic example which shows you how to print a generic greeting:
```{{r example}}
library(mypackage)
## basic example code
hello()
```
This is a basic example which shows you how to print a personalised greeting:
```{{r}}
hello(name = "Lucy Elen")
```
````
and renders to the following when **Knit**

#### {{< fa square-check >}} Let's commit our current files and changes.
# :vertical_traffic_light: Complete package metadata
Let's head to the `DESCRIPTION` file and complete the details.
## Authors
First let's complete the authors.
Remove the current author and maintainer lines and replace it with the following line:
```
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
```
completed with your own details
## Add a title and description
**Complete the title and description fields with appropriate details.**
If you want to form a paragraph of text, make sure do indent the hanging lines by 4 spaces (one tab). And make sure that your Description field **ends in a full-stop**.
## Add a date
Use today's date in ISO format, ie **`r config::get('pkgdev_date_iso')`**. This will populate a citation entry for us.
### Completed `DESCRIPTION`
The complete `DESCRIPTION` file should look something like this:
```
Package: mypackage
Title: Customised greetings from me!
Version: 0.0.0.9000
Authors@R: person("Anna", "Krystalli",
email = "annakrystalli@googlemail.com",
role = c("aut", "cre"))
Description: Prints a customised greeting from myself,
delivered by a friend.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
cowsay
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Date: 2024-04-19
```
Check your package. If all is good, document, install and restart!
Now, check you're package's citation:
```{r, eval=FALSE}
citation("mypackage")
```
```
To cite package ‘mypackage’ in publications use:
Krystalli A (2024). _mypackage: Customised
greetings from me!_. R package version 0.0.0.9000.
A BibTeX entry for LaTeX users is
@Manual{,
title = {mypackage: Customised greetings from me!},
author = {Anna Krystalli},
year = {2024},