1
1
# ' Creates the Rd files based on translated Roxygen scripts
2
- # ' @param folder Source sub-folder where the source Roxygen R scripts are
3
- # ' @param source_folder Base source folder where the different translations are located.
4
- # ' Defaults to 'man-lang'.
2
+ # ' @param source_sub_folder Source sub-folder where the source Roxygen R scripts
3
+ # ' are. Defaults to NULL. If left null, all of the sub-folders in the
4
+ # ' `source_folder` will be processed
5
+ # ' @param source_folder Base source folder where the different translations are
6
+ # ' located. Defaults to 'man-lang'.
5
7
# ' @param target_folder Base target folder where the different translations will be
6
8
# ' located. Defaults to 'inst/man-lang'
7
9
# ' @param r_folder Source of the original R scripts. Only used to see if the
8
10
# ' Roxygen documentation is different from what is capture in the `source_folder`
9
11
# ' @param pkg_path The path to the package
10
12
# ' @returns Multiple Rd files based on the source R scripts
11
13
# ' @export
12
- process_roxygen_folder <- function (
13
- folder ,
14
+ process_roxygen <- function (
15
+ source_sub_folder = NULL ,
16
+ source_folder = " man-lang" ,
17
+ target_folder = " inst/man-lang" ,
14
18
r_folder = " R" ,
19
+ pkg_path = " ." ) {
20
+ if (! dir_exists(path(pkg_path , source_folder ))) {
21
+ cli_abort(" Source folder: '{source_folder}', is not found" )
22
+ }
23
+ if (is.null(source_sub_folder )) {
24
+ compare_man_lang(
25
+ r_folder = r_folder ,
26
+ source_folder = source_folder ,
27
+ pkg_path = pkg_path
28
+ )
29
+ sub_folders <- dir_ls(path(pkg_path , source_folder ), type = " directory" )
30
+ sub_folders <- path_file(sub_folders )
31
+ } else {
32
+ sub_folders <- source_sub_folder
33
+ }
34
+ for (source_sub_folder in sub_folders ) {
35
+ process_roxygen_folder(
36
+ source_sub_folder = source_sub_folder ,
37
+ source_folder = source_folder ,
38
+ target_folder = target_folder ,
39
+ pkg_path = pkg_path
40
+ )
41
+ }
42
+ }
43
+
44
+ process_roxygen_folder <- function (
45
+ source_sub_folder = NULL ,
15
46
source_folder = " man-lang" ,
16
47
target_folder = " inst/man-lang" ,
17
48
pkg_path = " ." ) {
@@ -31,22 +62,27 @@ process_roxygen_folder <- function(
31
62
}
32
63
# Copies content of the translated script to the R folder
33
64
# of the temp copy
34
- source_path <- path(pkg_path , source_folder , folder )
65
+ source_path <- path(pkg_path , source_folder , source_sub_folder )
35
66
full_source <- dir_ls(path(source_path ), recurse = TRUE , glob = " *.R" )
36
67
file_copy(
37
68
path = full_source ,
38
69
new_path = path(copy_path , " R" ),
39
70
overwrite = TRUE
40
71
)
72
+ cli_alert_info(
73
+ paste0(
74
+ " Creating Rd files from {path_rel(source_path)}" ,
75
+ " ({to_title(from_iso639(source_sub_folder)[[1]]) })"
76
+ )
77
+ )
41
78
# Uses `callr` to run roxygenize, mainly to avoid the messages from roxygen2
42
- cli_h3(" Creating Rd files for '{folder}'" )
43
79
callr :: r_safe(
44
80
func = function (x ) roxygen2 :: roxygenize(x , roclets = " rd" ),
45
81
args = list (copy_path )
46
82
)
47
83
# Copies the new contents in 'man' from the temp copy
48
84
# into target folder, under the language's sub-folder
49
- target_path <- path(pkg_path , target_folder , folder )
85
+ target_path <- path(pkg_path , target_folder , source_sub_folder )
50
86
if (dir_exists(target_path )) {
51
87
dir_delete(target_path )
52
88
}
@@ -64,29 +100,6 @@ process_roxygen_folder <- function(
64
100
invisible ()
65
101
}
66
102
67
- # ' @rdname process_roxygen_folder
68
- # ' @export
69
- process_roxygen <- function (
70
- source_folder = " man-lang" ,
71
- target_folder = " inst/man-lang" ,
72
- r_folder = " R" ,
73
- pkg_path = " ." ) {
74
- sub_folders <- dir_ls(path(pkg_path , source_folder ), type = " directory" )
75
- compare_man_lang(
76
- r_folder = r_folder ,
77
- source_folder = source_folder ,
78
- pkg_path = pkg_path
79
- )
80
- for (folder in sub_folders ) {
81
- process_roxygen_folder(
82
- folder = path_file(folder ),
83
- source_folder = source_folder ,
84
- target_folder = target_folder ,
85
- pkg_path = pkg_path
86
- )
87
- }
88
- }
89
-
90
103
compare_man_lang <- function (
91
104
folder = NULL ,
92
105
r_folder = " R" ,
0 commit comments