File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
crates/ark/src/modules/positron Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 53
53
res_list
54
54
}
55
55
56
+ # ' Get the version of installed packages
57
+ # '
58
+ # ' This function retrieves the versions of specified packages in R.
59
+ # '
60
+ # ' It returns a named list where the names are the package names and the values
61
+ # ' are the corresponding package versions, or "Not installed" if the package is
62
+ # ' not found.
63
+ # '
64
+ # ' @export
65
+ .ps.rpc.get_package_versions <- function (package_names , ... ) {
66
+ lapply(set_names(package_names ), function (pkg ) {
67
+ if (is_on_disk(pkg )) {
68
+ as.character(utils :: packageVersion(pkg ))
69
+ } else {
70
+ " Not installed"
71
+ }
72
+ })
73
+ }
74
+
56
75
# ' Get available vignettes for a package
57
76
# '
58
77
# ' This function retrieves the vignettes available for a specified package in R.
Original file line number Diff line number Diff line change @@ -152,3 +152,32 @@ obj_address <- function(x) {
152
152
paste_line <- function (x ) {
153
153
paste(x , collapse = " \n " )
154
154
}
155
+
156
+ set_names <- function (x , names = x ) {
157
+ names(x ) <- x
158
+ x
159
+ }
160
+
161
+ # From rlang
162
+ is_on_disk <- function (pkg ) {
163
+ system_path(pkg ) != " "
164
+ }
165
+
166
+ system_path <- function (pkg ) {
167
+ # Important for this to be first because packages loaded with pkgload
168
+ # will have a different path than the one in `.libPaths()` (if any).
169
+ #
170
+ # Note that this will not work for the base package, since we can't call
171
+ # getNamespaceInfo on it.
172
+ if (isNamespaceLoaded(pkg ) && ! identical(pkg , " base" )) {
173
+ return (.getNamespaceInfo(asNamespace(pkg ), " path" ))
174
+ }
175
+
176
+ for (path in file.path(.libPaths(), pkg )) {
177
+ if (file.exists(path )) {
178
+ return (path )
179
+ }
180
+ }
181
+
182
+ " "
183
+ }
You can’t perform that action at this time.
0 commit comments