Title: | Get on to the Slides |
---|---|
Description: | Create tables from within R directly on Google Slides presentations. Currently supports matrix, data.frame and 'flextable' objects. |
Authors: | Isaac Gravestock [aut, cre] (orcid=0000-0003-0283-2065) |
Maintainer: | Isaac Gravestock <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.0.9006 |
Built: | 2025-03-10 13:37:59 UTC |
Source: | https://github.com/igrave/ladder |
Add Object to Slides
## S3 method for class 'data.frame' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, digits = NULL, ... ) ## S3 method for class 'flextable' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, ... ) add_to_slides(object, presentation_id, on = NULL, object_id, overwrite, ...) ## S3 method for class 'matrix' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, digits = NULL, ... )
## S3 method for class 'data.frame' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, digits = NULL, ... ) ## S3 method for class 'flextable' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, ... ) add_to_slides(object, presentation_id, on = NULL, object_id, overwrite, ...) ## S3 method for class 'matrix' add_to_slides( object, presentation_id, on = NULL, object_id = new_id("table"), overwrite = FALSE, digits = NULL, ... )
object |
An object to add to slides |
presentation_id |
The id from the Slides presentation |
on |
The id or number of the slide to add |
object_id |
A unique id for the new object on the slides |
overwrite |
If TRUE and an object with |
digits |
the minimum number of significant digits, see format. If |
... |
Other arguments used in methods |
A data.frame object is added as a table with the column names in bold as the first row.
For other formatting use the flextable
package and add_to_slides.flextable.
A flextable object is added with all formatting.
A matrix object is added as a table without any row or column names.
A presentation object after updating
## Add a data.frame s <- choose_slides() obj <- iris[1:5, ] add_to_slides(obj, s, on = 1) ## Add a flextable s <- choose_slides() library(flextable) ft <- flextable(iris[1:5, ]) ft <- theme_box(ft) ft <- color(ft, i = 1:3, j = 1:2, "pink", part = "body") ft <- autofit(ft) add_to_slides(ft, s, on = 1) ## Add a matrix s <- choose_slides() obj <- cov(iris[, 1:4]) add_to_slides(obj, s, on = 1)
## Add a data.frame s <- choose_slides() obj <- iris[1:5, ] add_to_slides(obj, s, on = 1) ## Add a flextable s <- choose_slides() library(flextable) ft <- flextable(iris[1:5, ]) ft <- theme_box(ft) ft <- color(ft, i = 1:3, j = 1:2, "pink", part = "body") ft <- autofit(ft) add_to_slides(ft, s, on = 1) ## Add a matrix s <- choose_slides() obj <- cov(iris[, 1:4]) add_to_slides(obj, s, on = 1)
Opens a webpage for a user to authenticate with Google and select a presentation. This presentation is then authorised for use with ladder.
choose_slides()
choose_slides()
A presentation id
id <- choose_slides()
id <- choose_slides()
Create a new Google Slides presentation
create_slides()
create_slides()
A presentation id
create_slides()
create_slides()
Get layouts from a presentation
get_layouts(presentation_id)
get_layouts(presentation_id)
presentation_id |
The presentation id |
A data frame with columns layout_objectId
, name
, displayName
, and placeholders_df
s <- choose_slides() get_layouts(s)
s <- choose_slides() get_layouts(s)
Get ids of objects on Slides
get_object_ids(presentation_id)
get_object_ids(presentation_id)
presentation_id |
character, the presentation id |
A list of character vectors of object ids. The list has elements for each page. If a
slide page has no objects the list element is NULL
otherwise a character vector containing
all object ids on that page. Contains ids for all tables, images, lines, shapes, etc.
s <- choose_slides() get_object_ids(s)
s <- choose_slides() get_object_ids(s)
Get ids of Slides pages
get_slide_ids(presentation_id)
get_slide_ids(presentation_id)
presentation_id |
character, the presentation id |
A vector of slide ids.
s <- choose_slides() get_slide_ids(s)
s <- choose_slides() get_slide_ids(s)
Authorize ladder to view and manage your presentations. This function is a
wrapper around gargle::token_fetch()
.
By default, you are directed to a web browser, asked to sign in to your Google account, and to grant ladder permission to operate on your behalf with Google Slides. By default, with your permission, these user credentials are cached in a folder below your home directory, from where they can be automatically refreshed, as necessary. Storage at the user level means the same token can be used across multiple projects and tokens are less likely to be synced to the cloud by accident.
ladder_auth( email = gargle::gargle_oauth_email(), path = NULL, subject = NULL, scopes = c("https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/presentations.currentonly"), cache = gargle::gargle_oauth_cache(), use_oob = gargle::gargle_oob_default(), token = NULL )
ladder_auth( email = gargle::gargle_oauth_email(), path = NULL, subject = NULL, scopes = c("https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/presentations.currentonly"), cache = gargle::gargle_oauth_cache(), use_oob = gargle::gargle_oob_default(), token = NULL )
email |
Optional. If specified,
Defaults to the option named |
path |
JSON identifying the service account, in one of the forms
supported for the |
subject |
An optional subject claim. Specify this if you wish to use the
service account represented by |
scopes |
A character vector of scopes to request. Pick from those listed at https://developers.google.com/identity/protocols/oauth2/scopes. |
cache |
Specifies the OAuth token cache. Defaults to the option named
|
use_oob |
Whether to use out-of-band authentication (or, perhaps, a
variant implemented by gargle and known as "pseudo-OOB") when first
acquiring the token. Defaults to the value returned by
If the OAuth client is provided implicitly by a wrapper package, its type
probably defaults to the value returned by
|
token |
A token with class Token2.0 or an object of
httr's class |
Most users, most of the time, do not need to call ladder_auth()
explicitly – it is triggered by the first action that requires
authorization. Even when called, the default arguments often suffice.
However, when necessary, ladder_auth()
allows the user to explicitly:
Declare which Google identity to use, via an email
specification.
Use a service account token or workload identity federation via
path
.
Bring your own token
.
Customize scopes
.
Use a non-default cache
folder or turn caching off.
Explicitly request out-of-band (OOB) auth via use_oob
.
If you are interacting with R within a browser (applies to RStudio
Server, Posit Workbench, Posit Cloud, and Google Colaboratory), you need
OOB auth or the pseudo-OOB variant. If this does not happen
automatically, you can request it explicitly with use_oob = TRUE
or,
more persistently, by setting an option via
options(gargle_oob_default = TRUE)
.
The choice between conventional OOB or pseudo-OOB auth is determined
by the type of OAuth client. If the client is of the "installed" type,
use_oob = TRUE
results in conventional OOB auth. If the client is of
the "web" type, use_oob = TRUE
results in pseudo-OOB auth. Packages
that provide a built-in OAuth client can usually detect which type of
client to use. But if you need to set this explicitly, use the
"gargle_oauth_client_type"
option:
options(gargle_oauth_client_type = "web") # pseudo-OOB # or, alternatively options(gargle_oauth_client_type = "installed") # conventional OOB
For details on the many ways to find a token, see
gargle::token_fetch()
. For deeper control over auth, use
ladder_auth_configure()
to bring your own OAuth client or API key.
To learn more about gargle options, see gargle::gargle_options.
Other auth functions:
ladder_auth_configure()
,
ladder_deauth()
# load/refresh existing credentials, if available # otherwise, go to browser for authentication and authorization ladder_auth() # see user associated with current token ladder_user() # force use of a token associated with a specific email ladder_auth(email = "[email protected]") ladder_user() # force the OAuth web dance ladder_auth(email = NA) # use a 'read only' scope, so it's impossible to edit or delete files ladder_auth(scopes = "slides.readonly") # use a service account token ladder_auth(path = "foofy-83ee9e7c9c48.json")
# load/refresh existing credentials, if available # otherwise, go to browser for authentication and authorization ladder_auth() # see user associated with current token ladder_user() # force use of a token associated with a specific email ladder_auth(email = "[email protected]") ladder_user() # force the OAuth web dance ladder_auth(email = NA) # use a 'read only' scope, so it's impossible to edit or delete files ladder_auth(scopes = "slides.readonly") # use a service account token ladder_auth(path = "foofy-83ee9e7c9c48.json")
These functions give more control over and visibility into the auth
configuration than ladder_auth()
does. ladder_auth_configure()
lets the user specify their own:
OAuth client, which is used when obtaining a user token.
API key. If ladder is de-authorized via ladder_deauth()
, all
requests are sent with an API key in lieu of a token.
See the vignette("get-api-credentials", package = "gargle")
for more.
If the user does not configure these settings, internal defaults
are used.
ladder_oauth_client()
and ladder_api_key()
retrieve the
currently configured OAuth client and API key, respectively.
ladder_auth_configure(client, path, api_key, app) ladder_api_key() ladder_oauth_client()
ladder_auth_configure(client, path, api_key, app) ladder_api_key() ladder_oauth_client()
client |
A Google OAuth client, presumably constructed via
|
path |
JSON downloaded from Google Cloud Console, containing a client id and
secret, in one of the forms supported for the |
api_key |
API key. |
app |
ladder_auth_configure()
: An object of R6 class
gargle::AuthState, invisibly.
ladder_oauth_client()
: the current user-configured OAuth client.
ladder_api_key()
: the current user-configured API key.
Other auth functions:
ladder_auth()
,
ladder_deauth()
# see and store the current user-configured OAuth client (probaby `NULL`) (original_client <- ladder_oauth_client()) # see and store the current user-configured API key (probaby `NULL`) (original_api_key <- ladder_api_key()) # the preferred way to configure your own client is via a JSON file # downloaded from Google Developers Console # this example JSON is indicative, but fake path_to_json <- system.file( "extdata", "client_secret_installed.googleusercontent.com.json", package = "gargle" ) ladder_auth_configure(path = path_to_json) # this is also obviously a fake API key ladder_auth_configure(api_key = "the_key_I_got_for_a_google_API") # confirm the changes ladder_oauth_client() ladder_api_key() # restore original auth config ladder_auth_configure(client = original_client, api_key = original_api_key)
# see and store the current user-configured OAuth client (probaby `NULL`) (original_client <- ladder_oauth_client()) # see and store the current user-configured API key (probaby `NULL`) (original_api_key <- ladder_api_key()) # the preferred way to configure your own client is via a JSON file # downloaded from Google Developers Console # this example JSON is indicative, but fake path_to_json <- system.file( "extdata", "client_secret_installed.googleusercontent.com.json", package = "gargle" ) ladder_auth_configure(path = path_to_json) # this is also obviously a fake API key ladder_auth_configure(api_key = "the_key_I_got_for_a_google_API") # confirm the changes ladder_oauth_client() ladder_api_key() # restore original auth config ladder_auth_configure(client = original_client, api_key = original_api_key)
Put ladder into a de-authorized state. Instead of sending a token,
ladder will send an API key. This can be used to access public
resources for which no Google sign-in is required. This is handy for using
ladder in a non-interactive setting to make requests that do not
require a token. It will prevent the attempt to obtain a token
interactively in the browser. The user can configure their own API key
via ladder_auth_configure()
and retrieve that key via
ladder_api_key()
.
In the absence of a user-configured key, a built-in default key is used.
ladder_deauth()
ladder_deauth()
Other auth functions:
ladder_auth()
,
ladder_auth_configure()
## Not run: ladder_deauth() ladder_user() ## End(Not run)
## Not run: ladder_deauth() ladder_user() ## End(Not run)
Reports whether ladder has stored a token, ready for use in downstream requests.
ladder_has_token()
ladder_has_token()
Logical.
Other low-level API functions:
ladder_token()
ladder_has_token()
ladder_has_token()
For internal use or for those programming around the Slides API.
Returns a token pre-processed with httr::config()
. Most users
do not need to handle tokens "by hand" or, even if they need some
control, ladder_auth()
is what they need. If there is no current
token, ladder_auth()
is called to either load from cache or
initiate OAuth2.0 flow.
If auth has been deactivated via ladder_deauth()
, ladder_token()
returns NULL
.
ladder_token()
ladder_token()
A request
object (an S3 class provided by httr).
Other low-level API functions:
ladder_has_token()
## Not run: ladder_token() ## End(Not run)
## Not run: ladder_token() ## End(Not run)
Reveals the email address of the user associated with the current token. If no token has been loaded yet, this function does not initiate auth.
ladder_user()
ladder_user()
An email address or, if no token has been loaded, NULL
.
gargle::token_userinfo()
, gargle::token_email()
,
gargle::token_tokeninfo()
## Not run: ladder_user() ## End(Not run)
## Not run: ladder_user() ## End(Not run)
Add a slide to a presentation
new_slide( presentation_id, layout, centered_title = NULL, subtitle = NULL, title = NULL, body = NULL )
new_slide( presentation_id, layout, centered_title = NULL, subtitle = NULL, title = NULL, body = NULL )
presentation_id |
The presentation id |
layout |
The layout to use for the slide. See get_layouts. |
centered_title |
Character vector to be inserted into the "centered_title" placeholders in
order as for |
subtitle |
Character vector to be inserted into the subtitle placeholders in order as for
|
title |
Character vector to be inserted into the title placeholders in order. Any |
body |
Character vector to be inserted into the body placeholders in order as for |
The result of the API call. TODO format this object
s <- create_slides() layout <- get_layouts(s) layout_p9 <- layout$layout_objectId[20] new_slide(s, layout_p9, title = "Slide Title", subtitle = "A Subtitle", body = "Body Text")
s <- create_slides() layout <- get_layouts(s) layout_p9 <- layout$layout_objectId[20] new_slide(s, layout_p9, title = "Slide Title", subtitle = "A Subtitle", body = "Body Text")
Print presentation URL
slides_url(presentation_id, slide_id = NULL)
slides_url(presentation_id, slide_id = NULL)
presentation_id |
ID of presentation |
slide_id |
Optional slide id to link directly to a certain slide. See get_slide_ids. |
Prints URL as a link and invisibly returns URL.
slides_url("example_id_won't_work_1234567asdfbg") slides_url("example_id_won't_work_1234567asdfbg", slide_id = "p")
slides_url("example_id_won't_work_1234567asdfbg") slides_url("example_id_won't_work_1234567asdfbg", slide_id = "p")
Use a Google token from github auth workflow
use_gauth_workflow(access_token)
use_gauth_workflow(access_token)
access_token |
The access token from github auth workflow |
Preview Slide as Image
view_slide(presentation_id, page, size = "MEDIUM", viewer = TRUE)
view_slide(presentation_id, page, size = "MEDIUM", viewer = TRUE)
presentation_id |
character, the presentation id |
page |
character, the page number or id |
size |
character, the size of the image. One of "SMALL", "MEDIUM", "LARGE" |
viewer |
logical, if TRUE opens the image in the viewer |
A character string of the file path to the saved image and
opens the image in the viewer or browser if viewer = TRUE
.