@@ -176,10 +176,10 @@ def _jupyterlab_variableinspector_dict_list():
176
176
vardic = [
177
177
{
178
178
'varName': _v,
179
- 'varType': type(eval(_v)).__name__,
180
- 'varSize': str(_jupyterlab_variableinspector_getsizeof(eval(_v))),
181
- 'varShape': str(_jupyterlab_variableinspector_getshapeof(eval(_v))) if _jupyterlab_variableinspector_getshapeof(eval(_v)) else '',
182
- 'varContent': str(_jupyterlab_variableinspector_getcontentof(eval(_v))),
179
+ 'varType': type(eval(_v)).__name__,
180
+ 'varSize': str(_jupyterlab_variableinspector_getsizeof(eval(_v))),
181
+ 'varShape': str(_jupyterlab_variableinspector_getshapeof(eval(_v))) if _jupyterlab_variableinspector_getshapeof(eval(_v)) else '',
182
+ 'varContent': str(_jupyterlab_variableinspector_getcontentof(eval(_v))),
183
183
'isMatrix': _jupyterlab_variableinspector_is_matrix(eval(_v)),
184
184
'isWidget': _jupyterlab_variableinspector_is_widget(type(eval(_v)))
185
185
}
@@ -226,7 +226,7 @@ def _jupyterlab_variableinspector_displaywidget(widget):
226
226
227
227
228
228
def _jupyterlab_variableinspector_default(o):
229
- if isinstance(o, __np.number): return int(o)
229
+ if isinstance(o, __np.number): return int(o)
230
230
raise TypeError
231
231
232
232
@@ -236,10 +236,10 @@ def _jupyterlab_variableinspector_deletevariable(x):
236
236
237
237
static r_script = `library(repr)
238
238
239
- .ls.objects = function (pos = 1, pattern, order.by, decreasing = FALSE, head = FALSE,
240
- n = 5)
239
+ .ls.objects = function (pos = 1, pattern, order.by, decreasing = FALSE, head = FALSE,
240
+ n = 5)
241
241
{
242
- napply <- function(names, fn) sapply(names, function(x) fn(get(x,
242
+ napply <- function(names, fn) sapply(names, function(x) fn(get(x,
243
243
pos = pos)))
244
244
names <- ls(pos = pos, pattern = pattern)
245
245
if (length(names) == 0) {
@@ -251,11 +251,11 @@ def _jupyterlab_variableinspector_deletevariable(x):
251
251
obj.size <- napply(names, object.size)
252
252
obj.dim <- t(napply(names, function(x) as.numeric(dim(x))[1:2]))
253
253
obj.content <- rep("NA", length(names))
254
- has_no_dim <- is.na(obj.dim)[1:length(names)]
254
+ has_no_dim <- is.na(obj.dim)[1:length(names)]
255
255
obj.dim[has_no_dim, 1] <- napply(names, length)[has_no_dim]
256
256
vec <- (obj.type != "function")
257
257
obj.content[vec] <- napply(names[vec], function(x) toString(x, width = 154)[1])
258
-
258
+
259
259
obj.rownames <- napply(names, rownames)
260
260
has_rownames <- obj.rownames != "NULL"
261
261
obj.rownames <- sapply(obj.rownames[has_rownames], function(x) paste(x,
@@ -264,24 +264,24 @@ def _jupyterlab_variableinspector_deletevariable(x):
264
264
obj.rownames <- ifelse(nchar(obj.rownames) > 154, obj.rownames.short, obj.rownames)
265
265
obj.rownames <- sapply(obj.rownames, function(x) paste("Row names: ",x))
266
266
obj.content[has_rownames] <- obj.rownames
267
-
268
-
267
+
268
+
269
269
obj.colnames <- napply(names, colnames)
270
270
has_colnames <- obj.colnames != "NULL"
271
- obj.colnames <- sapply(obj.colnames[has_colnames], function(x) paste(x,
271
+ obj.colnames <- sapply(obj.colnames[has_colnames], function(x) paste(x,
272
272
collapse = ", "))
273
- obj.colnames.short <- sapply(obj.colnames, function(x) paste(substr(x,
273
+ obj.colnames.short <- sapply(obj.colnames, function(x) paste(substr(x,
274
274
1, 150), "...."))
275
- obj.colnames <- ifelse(nchar(obj.colnames) > 154, obj.colnames.short,
275
+ obj.colnames <- ifelse(nchar(obj.colnames) > 154, obj.colnames.short,
276
276
obj.colnames)
277
277
obj.colnames <- sapply(obj.colnames, function(x) paste("Column names: ",x))
278
-
278
+
279
279
obj.content[has_colnames] <- obj.colnames
280
-
280
+
281
281
is_function <- (obj.type == "function")
282
282
obj.content[is_function] <- napply(names[is_function], function(x) paste(strsplit(repr_text(x),")")[[1]][1],")",sep=""))
283
283
obj.content <- unlist(obj.content, use.names = FALSE)
284
-
284
+
285
285
286
286
out <- data.frame(obj.type, obj.size, obj.dim)
287
287
names(out) <- c("varType", "varSize", "Rows", "Columns")
@@ -292,10 +292,10 @@ def _jupyterlab_variableinspector_deletevariable(x):
292
292
out <- out[, !(names(out) %in% c("Rows", "Columns"))]
293
293
rownames(out) <- NULL
294
294
print(out)
295
- if (!missing(order.by))
296
- out <- out[order(out[[order.by]], decreasing = decreasing),
295
+ if (!missing(order.by))
296
+ out <- out[order(out[[order.by]], decreasing = decreasing),
297
297
]
298
- if (head)
298
+ if (head)
299
299
out <- head(out, n)
300
300
jsonlite::toJSON(out)
301
301
}
0 commit comments