Skip to content

Instantly share code, notes, and snippets.

@dtenenba
Created April 29, 2024 17:01
Show Gist options
  • Save dtenenba/6543588b2a92582be1e65ac6a3d73568 to your computer and use it in GitHub Desktop.
Save dtenenba/6543588b2a92582be1e65ac6a3d73568 to your computer and use it in GitHub Desktop.
"""
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