Package 'promoutils'

Title: Utilities for Promoting rOpenSci on Twitter
Description: Utility functions for accessing GitHub and twitter data.
Authors: Steffi LaZerte [aut, cre] (ORCID: <https://orcid.org/0000-0002-7690-8360>)
Maintainer: Steffi LaZerte <[email protected]>
License: GPL (>= 3)
Version: 0.4.3
Built: 2025-05-26 10:30:01 UTC
Source: https://github.com/ropensci-org/promoutils

Help Index


Fetch GH and Mastodon usernames

Description

Based on a name and a repository, fetch the usernames

Usage

all_users(name, owner = "ropensci", pkg)

Arguments

name

Character. Full name

owner

Character. Repository owner.

pkg

Character. Repository name (package name).

Value

Data frame of user names: gh_user and masto_user

Examples

all_users(name = "Steffi LaZerte", pkg = "weathercan")

Create draft message for checking in with Cohosts

Description

The week before, prepare the slides and coworking document, then use this draft text to invite the cohost(s) to review via Slack or Email.

Usage

cw_checkin(which = "next", names = NULL, notes_link, slides_link)

Arguments

which

Character/Date. "next" to fetch details on the next coworking session, "last" to fetch details on the last scheduled (in future) coworking session, or a Date fetch details for a specific coworking session.

names

Character. Names of cohost if overriding those in the event listing.

notes_link

Character. Link to the Google doc with coworking notes.

slides_link

Character. Link to the Google slides.


Fetch details about coworking sessions

Description

Fetch details about coworking sessions

Usage

cw_details(which = "next")

Arguments

which

Character/Date. "next" to fetch details on the next coworking session, "last" to fetch details on the last scheduled (in future) coworking session, or a Date fetch details for a specific coworking session.

Value

Data frame with coworking event details

Examples

cw_details()
cw_details("2023-11")

Create a draft event for coworking

Description

Creates a draft coworking event for the roweb3 website. All details pulled from the coworking todo list issue in rosadmin/comms.

Usage

cw_event(date, dry_run = FALSE)

Arguments

date

Character/Date. Date of the coworking event (local)

dry_run

Logical. Whether to really create the event or just return the text.


Create Coworking To-Do's on Comms Repo

Description

Create an issue listing the coworking todos. If no date or timezone, picks the next appropriate date (first Tuesday in the month following an existing coworking issue) and next appropriate timezone (cycling through America, Europe, and Australia) automatically.

Usage

cw_issue(
  date = NULL,
  tz = NULL,
  theme = "XXXX",
  cohost = "XXXX",
  dry_run = FALSE
)

Arguments

date

Character. Date of next event (if NULL picks next first Tuesday).

tz

Character. Timezone of next event (if NULL picks next in order).

theme

Character. Name of theme, if unknown, uses XXXX placeholder

cohost

Character. Name of cohost, if unknown, uses XXXX placeholder

dry_run

Logical. Whether to do a dry run (i.e. don't post)


Create a draft post for coworking

Description

Creates draft posts for Mastodon and LinkedIn (by opening issues on rosadmin/scheduled_socials) and Slack (by printing the post text and schedule).

Usage

cw_socials(
  date,
  who_masto,
  who_slack,
  who_linkedin,
  who_main_masto = "@[email protected]",
  who_main_slack = "@Steffi LaZerte",
  who_main_linkedin = "Steffi LaZerte",
  posters_tz = "America/Winnipeg",
  dry_run = FALSE
)

Arguments

date

Character/Date. Date of the coworking event (local)

who_masto

Character. The full mastodon handle for the cohost (i.e. [email protected])

who_slack

Character. The full Slack handle for the cohost (i.e. @XXXX)

who_linkedin

Character. The full LinkedIn handle for the cohost (i.e. @XXXX)

who_main_masto

Character. The full mastodon handle for the rOpenSci staff organizer.

who_main_slack

Character. The full Slack handle for the rOpenSci staff organizer.

who_main_linkedin

Character. The full LinkedIn handle for the rOpenSci staff organizer.

posters_tz

Character. Timezone of poster. Required for getting the time at which to post Slack messages as these are posted in the local timezone

dry_run

Logical. Whether to do a dry run (i.e. don't post)

Examples

## Not run: 
cw_socials("2023-07-04", who_masto = "@[email protected]", who_slack = "@cohost")

## End(Not run)

Fetch full name of Discourse user (id)

Description

Using the Discourse username id, return the full name of that discourse user.

Usage

discourse_user(user)

Arguments

user_id

Integer. Discourse user id.

Value

Character

Examples

# discourse_user(1) # Requires authentication

Extract mentions from forum text

Description

Extract mentions from forum text

Usage

forum_mention(x)

Arguments

x

Forum text

Value

Character of metions


Fetch post text from by topic id

Description

Fetch post text from by topic id

Usage

forum_post(topic_id)

Arguments

x

Topic id

Value

HTML of the post

Examples

# forum_post(3920) # Needs auth

Extract resources from forum text

Description

Extract resources from forum text

Usage

forum_resource(x)

Arguments

x

Forum text

Value

Character vector of resources

Examples

# forum_post(3920) |> # Needs auth
#   forum_resource()  # > weatherOz

Create a cached version of the GH api calls

Description

Create a cached version of the GH api calls

Usage

gh_cache(
  endpoint,
  ...,
  per_page = NULL,
  .per_page = NULL,
  .token = NULL,
  .destfile = NULL,
  .overwrite = FALSE,
  .api_url = NULL,
  .method = "GET",
  .limit = NULL,
  .accept = "application/vnd.github.v3+json",
  .send_headers = NULL,
  .progress = TRUE,
  .params = list(),
  .max_wait = 600,
  .max_rate = NULL
)

Details

memoise::memoise(gh::gh)


Fetch issues from a GH repository

Description

Fetch issues from a GH repository

Usage

gh_issue_fetch(
  state = "open",
  labels = NULL,
  since = NULL,
  owner = "rosadmin",
  repo = "scheduled_socials",
  issue = NULL,
  verbose = FALSE
)

Arguments

state

Character. Which issues to fetch: "open", "closed", "all"

labels

Character vector. Fetch only issues with these labels. (Optional)

since

Character/Date/datetime. Fetch only issues since this date/time. (Optional)

owner

Character. Owner of the repository

repo

Character. Name of the repository (name of the package)

issue

Numeric. Specific Issue number to fetch.

verbose

Logical. Show progress messages.

Value

List of issues

Examples

i <- gh_issue_fetch()

Format issues list from GH

Description

Format issues list from GH

Usage

gh_issue_fmt(
  i,
  which = c("title", "number", "body", "labels", "url", "created", "updated",
    "gh_user_issue")
)

Arguments

i

List of issues from gh_issue_fetch()

which

Which fields to includ

Value

Issues formated as a data frame

Examples

i <- gh_issue_fetch()
i <- gh_issue_fmt(i, which = "title")

Extract information on help-wanted labels for issues

Description

Extract information on help-wanted labels for issues

Usage

gh_issue_labels(
  i,
  labels_help = "(help)|(help wanted)|(help-wanted)|(help_wanted)",
  labels_first = "(good first issue)|(beginner)|(good-first-issue)"
)

Arguments

i

Data frame of issues from gh_issue_fmt()

labels_help

Character. Regular expression to match help-wanted labels.

labels_first

Character. Regular expression to meatch good-first-issue labels.

Value

data frame with added label details

Examples

i <- gh_issue_fetch(owner = "ropensci", repo = "weathercan")
i <- gh_issue_fmt(i)
i <- gh_issue_labels(i)

Find Mastodon username from GitHub profile

Description

Find Mastodon username from GitHub profile

Usage

gh_masto(gh_user)

Arguments

gh_user

Character. GH username

Value

Character URL to mastodon profile if it exists, NA otherwise.

Examples

gh_masto("steffilazerte")

Fetch full name of GitHub user

Description

Fetch full name of GitHub user

Usage

gh_name(gh_user)

Arguments

gh_user

Character. GitHub username/handle

Value

Character, full name of the user or NA

Examples

gh_name("steffilazerte")

Find GH username from repository and full name

Description

Look up users of a repository and match to a name. Try with and without initials.

Usage

gh_user(name, owner = "ropensci", pkg, .max_rate = NULL)

Arguments

name

Character. Full or partial name of the person for whom you want to fetch the GitHub username.

owner

Character. Owner of the repository.

pkg

Character. Repository name (package name).

.max_rate

Numeric. Passed through to gh:gh().

Value

Data frame with names attempted and usernames found

Examples

gh_user(name = "Steffi E. LaZerte", owner = "ropensci", pkg = "weathercan")
gh_user(name = "Steffi", owner = "ropensci", pkg = "weathercan")

Authorize rOpenSci client with LinkedIn

Description

This authorizes the rOpenSci client with your credentials (and you must be part of the rOpenSci organization as an admin). Make sure to take note of the 'refresh_token' as that is what you'll add to your .Renviron file for local work, or the GitHub secrets for the comms/scheduled_socials workflow.

Usage

li_auth()

Details

This function authorizes with a redirect url of "http://localhost:1444/", this must be the same as that listed in the LinkedIn Developer App, https://www.linkedin.com/developers/apps.

If you retrieve a new token, you will have to put it in the .Renviron and the re-start your R session to continue

This function authorizes with the scopes:

  • w_member_social (default)

  • w_organization_social (special request)

  • r_organization_social (special request)

  • r_organization_admin (special request)

Value

httr2 authorization

References

  • Refresh tokens API: https://learn.microsoft.com/en-us/linkedin/shared/authentication/programmatic-refresh-tokens

Examples

## Not run: 
# Only run if you need to update the scopes or get a new token (otherwise
# you'll have to replace all your tokens)
t <- li_auth()
t$refresh_token

## End(Not run)

Get a list of recent posts by rOpenSci

Description

Get a list of recent posts by rOpenSci

Usage

li_posts_read(author)

Arguments

author

Character. LinkedIn URN id (e.g., rOpenSci's is "urn:li:organization:77132573")

Value

list of posts

References

  • https://learn.microsoft.com/en-us/linkedin/shared/api-guide/concepts/urns

  • https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/posts-api

Examples

li_posts_read(ro_urn)

Post to LinkedIn

Description

Post to LinkedIn

Usage

li_posts_write(author, body, dry_run = FALSE)

Arguments

author

Character. URN. Either yours (see li_urn_me() or rOpenSci's "urn:li:organization:77132573")

body

Character. The body of the post as you would like it to appear.

dry_run

Logical. TRUE to show what would be sent to the server without actually sending it.

Value

A string of the URN for the post id.

Examples

# Dry-run
id <- li_posts_write(
  author = ro_urn, # Post on behalf of rOpenSci
  body = "Testing out the LinkedIn API via R and httr2!",
  dry_run = TRUE)

## Not run: 
# Real post
id <- li_posts_write(
  author = ro_urn, # Post on behalf of rOpenSci
  body = "Testing out the LinkedIn API via R and httr2!")

## End(Not run)

Fetch your personal URN number

Description

This is required to post on LinkedIn to your personal account (for rOpenSci, use the organization urn, "urn:li:organization:77132573"

Usage

li_urn_me()

Value

A string with your URN in the format of "urn:li:person:XXXX"

Examples

## Not run: 
li_urn_me()

## End(Not run)

Fetch Mastodon username

Description

Using the GH username or the Full name, check rOpenSci author pages and then GitHub for references to the person Mastodon account.

Usage

masto_user(gh_user = NULL, name = NULL)

Arguments

gh_user

Character. GH user name.

name

Character. Full/Partial name

Value

Character url to Mastodon profile

Examples

masto_user("steffilazerte")

Convert a mastodon user link to handle

Description

Convert a mastodon user link to handle

Usage

masto2user(x)

Arguments

x

Character. Link to user's profile

Value

Character user handle @user@instance

Examples

masto2user("https://fosstodon.org/@steffilazerte")
masto2user("steffi")
masto2user("@[email protected]")
masto2user(NA)

Find the next date

Description

Given a date and a day of the week, Given a date return the next month's first Tuesday

Usage

next_date(month, which = "Tues", n = 1)

Arguments

month

Character/Date. The current month. Date returned is the next month.

which

Character/Numeric. Which week day to return. Either number or abbreviated English weekday.

n

Numeric. The nth week to return (i.e. the 1st Tuesday if n = 1 and which = "Tues").

Value

A date

Examples

# Get the next first Tuesday
next_date("2023-11-01")
next_date("2023-11-30")

# Get the next 3rd Tuesday
next_date("2023-11-01", n = 3)

# Oops
## Not run: 
next_date("2023-11-01", n = 5)

## End(Not run)

Get package author names

Description

Get package author names

Usage

pkg_authors(x, pkgs)

Arguments

x

Character. Package name

pkgs

Data frame. Packages returned by pkgs().

Value

Character name of maintainer


Return a data frame of rOpenSci packages

Description

Return a data frame of rOpenSci packages

Usage

pkgs(
  url = "https://ropensci.github.io/roregistry/registry.json",
  which = "active",
  return = "sub"
)

Arguments

url

Character. Registry url

which

Character. Status of packages to return ("all" or "active")

return

Character. Return a subset ("sub") or all ("all") package fields.

Value

data frame

Examples

pkgs()
pkgs(which = "all", return = "all")

Replace emoji codes with unicode

Description

Replaces emoji codes like :tada: with unicode like 🎉.

Usage

replace_emoji(x)

Arguments

x

Character. Text string within which to replace codes

Value

Text string with emoji unicodes

Examples

x <- replace_emoji("hi :tada: testing \n\n\n Whow ! 🔗 \n\n\n :smile:")
x

Find Mastodon username from rOpenSci author pages

Description

Find Mastodon username from rOpenSci author pages

Usage

ro_masto(name)

Arguments

name

Character. Full name as on RO author pages

Value

Character URL to mastodon profile if it exists, NA otherwise.

Examples

ro_masto("Steffi LaZerte")

Create a draft issue to post to Mastodon and LinkedIn

Description

Formats the body and title of an issue and posts it on "rosadmin/scheduled_socials". The issue will bed opened in a browser for editing and confirmation. Note that issues will not be posted until the labels "draft" and "needs-review" have been removed.

Usage

socials_post_issue(
  time,
  tz = "America/Winnipeg",
  title,
  body,
  where = "mastodon",
  avoid_dups = TRUE,
  add_hash = TRUE,
  dry_run = FALSE,
  open_browser = TRUE,
  over_char_limit = stop,
  verbose = FALSE
)

Arguments

time

Date/time. Date and time at which the post should be made

tz

Character. Timezone (from OlsonNames()) in which to post

title

Character. Title of the post (⁠[Post]⁠ and the date will be prepended and appended

body

Character. Text to be posted (omit the YAML for posting info; #RStats and @[email protected] will be appended for Mastodon, #RStats for LinkedIn), or link to text file with both Mastodon and LinkedIn body text, headed by by —- Mastodon —– and — LinkedIn —–.

where

Character vector. Either mastodon and/or linkedin to specify which platforms this should be posted on.

avoid_dups

Logical. Don't post an issue if any open issue has the same title.

add_hash

Logical. Whether to automatically add the RStats hashtags.

dry_run

Logical. Whether to perform a dry run (do not post, but display draft if verbose = TRUE).

open_browser

Logical. Whether to open the issue in the browser.

over_char_limit

Function. Stop or warn if over the character limit?

verbose

Logical. If dry run, displace draft?


Extract YAML keys from block

Description

Extract YAML keys from block

Usage

yaml_extract(yaml, trim = "~~~")

Arguments

yaml

Character. String from which to extract YAML keys

trim

Character. Text to remove from the YAML block before processing. Usually the text that defines the block.

Value

data frame of yaml keys

Examples

yaml_extract("~~~start: 2023-11-12\nauthor: Steffi\n~~~")