Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show number of rows in rdired #1234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion etc/ESSR/R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,15 @@
mode <- sapply(objs, data.class)
length <- sapply(objs, length)
size <- sapply(objs, function(obj) format(object.size(obj)))
d <- data.frame(mode, length, size)
rows <- sapply(objs,nrow)
# sapply returns a list rather than a vector if there are NULLs eg nrow returns NULL for non-dataframes.
# check if list, replace NULLS with NA and convert to vector
if (is.list(rows)) {
rows[sapply(rows,is.null)] <- NA
rows <- unlist(rows)
}

d <- data.frame(mode, length, rows, size)

var.names <- row.names(d)

Expand Down
14 changes: 12 additions & 2 deletions lisp/ess-rdired.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ can then examine these objects, plot them, and so on."
`[("Name" 18 t)
("Class" 10 t)
("Length" 10 ess-rdired--length-predicate)
("Rows" 10 ess-rdired--rows-predicate)
("Size" 10 ess-rdired--size-predicate)])
(add-hook 'tabulated-list-revert-hook #'ess-rdired-refresh nil t)
(when (and (not ess-rdired-auto-update-timer)
Expand Down Expand Up @@ -173,7 +174,7 @@ details."

(defun ess-rdired--tabulated-list-entries (text)
"Return a value suitable for `tabulated-list-entries' from TEXT."
(let (name class length size)
(let (name class length rows size)
(if (not (string-match-p " +\"" text))
;; Normal-world
(setq text (split-string text " " t)
Expand All @@ -185,13 +186,15 @@ details."
text (split-string (substring text (1+ (match-end 0))) " " t)))
(setq class (nth 0 text)
length (nth 1 text)
size (nth 2 text))
rows (nth 2 text)
size (nth 3 text))
(list name
`[(,name
help-echo "mouse-2, RET: View this object"
action ess-rdired-view)
,class
,length
,rows
,size])))

(defun ess-rdired-edit ()
Expand Down Expand Up @@ -274,6 +277,13 @@ Return t if A's length is < than B's length."
(lenB (aref (cadr B) 2)))
(< (string-to-number lenA) (string-to-number lenB))))

(defun ess-rdired--rows-predicate (A B)
"Enable sorting by rows in `ess-rdired' buffers.
Return t if A's length is < than B's length."
(let ((lenA (aref (cadr A) 2))
(lenB (aref (cadr B) 2)))
(< (string-to-number lenA) (string-to-number lenB))))

(defun ess-rdired--size-predicate (A B)
"Enable sorting by size in `ess-rdired' buffers.
Return t if A's size is < than B's size."
Expand Down