Created
April 29, 2024 17:01
-
-
Save dtenenba/6543588b2a92582be1e65ac6a3d73568 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given the lines in a sessionInfo() that start (minus whitespace) with `[`, | |
this creates a dict of package name/version pairs. | |
""" | |
def get_pkgs(text): | |
""" | |
Get a dict of package/version pairs from the packages section | |
of R's sessionInfo() output. | |
""" | |
out = {} | |
lines = text.split("\n") | |
for line in lines: | |
line = line.strip() | |
if not line.startswith("["): | |
continue | |
segs = line.split() | |
del segs[0] | |
for seg in segs: | |
pkg, ver = seg.rsplit("_", 1) | |
out[pkg] = ver | |
return out | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment