Error in parse_aws_s3_response, Forbidden (http 403) - r

I a
I'm trying to use aws.s3 library to load data into S3. Below is my code below:
Sys.setenv("AWS_ACCESS_KEY_ID" = ".............",
"AWS_SECRET_ACCESS_KEY" = "...............",
"AWS_DEFAULT_REGION" = "......")
view bucket:
get_bucket(bucket = "....",
check_region = FALSE,
verbose = TRUE)
The code above works and contents of the bucket is returned.
save object to s3:
s3save(data,
object = ".....",
bucket = ".....")
Error return:
List of 4
$ Code : chr "AccessDenied"
$ Message : chr "Access Denied"
$ RequestId: chr ""
$ HostId : chr ""
- attr(*, "headers")=List of 6
..$ x-amz-request-id : chr ""
..$ x-amz-id-2 : chr ""
..$ content-type : chr "application/xml"
..$ transfer-encoding: chr "chunked"
..$ date : chr "Tue, 05 Sep 2017 13:23:42 GMT"
..$ server : chr "AmazonS3"
..- attr(*, "class")= chr [1:2] "insensitive" "list"
- attr(*, "class")= chr "aws_error"
- attr(*, "request_canonical")= chr "GET\n/"| __truncated__
- attr(*, "request_string_to_sign")= car ""| __truncated__
- attr(*, "request_signature")= chr "AWS4-HMAC-SHA256 Credential=|
__truncated__
NULL
Error in parse_aws_s3_response(r, Sig, verbose = verbose) :
Forbidden (HTTP 403).
Any solution to this problem.

It seems like your IAM account is not authorized to do that operation.
If you're the owner of the AWS account, you can go to AWS Service IAM, click on users, choose this IAM user and add the necessary authorizations to it.

I got the same error message when attempting
get_bucket("collidr-api")
All I needed to do was add the region name like so
get_bucket("collidr-api", region="asia-south-01")
Then it worked. I found that info here.

#audiracmichelle, #Prakhar, use the function put_object from aws.s3 library as shown below. The object input argument to function put_object is the name(string) the object should have in s3.
You can first write a serialized object (in this case data) from memory with:
in_mem_obj <- rawConnection(raw(0), "w")
utils::write.table(data, in_mem_obj, sep = "\t", na = "", quote = TRUE,
row.names = FALSE, fileEncoding="UTF-8")
Then save object to S3 bucket:
put_object(rawConnectionValue(in_mem_obj),
object = FILEPATH/FILENAME,
bucket = BUCKET,
headers = c('x-amz-server-side-encryption' = 'AES256'),
key = AWS_ACCESS_KEY_ID,
secret = AWS_SECRET_ACCESS_KEY,
region = AWS_REGION,
check_region = FALSE)

Related

Request to API using httr2 not changing like httr

I'm trying to switch from the R package httr to httr2
httr2 is the modern rewrite and should be superior, but I'm a novice when it comes to APIs and coding and I've been stuck all day trying to figure out what I'm doing wrong. I can only get httr to work with this API.
I believe I am messing up with adding the headers, as I don't think the path sent to the API is changing. So my problem is the request gets rejected simply because the API can't read my API key.
Here is what I have done in httr2:
gov_url <- "https://api.dummy.gov/aaa/bb/cc"
resp <- request(gov_url) %>%
req_headers(
param1 = "10",
api_key = "abcdefg",
param2 = "xyz",
param3 = "09/10/2022"
) %>%
req_dry_run()
Output:
GET /destiny/v1/placeholder HTTP/1.1
Host: api.dummy.gov
User-Agent: httr2/0.2.1 r-curl/4.3.2 libcurl/7.64.1
Accept: */*
Accept-Encoding: deflate, gzip
param1: 10
api_key: abcdefg
param2: xyz
param3: 09/10/2022
The first line of that output hasn't changed.
GET /destiny/v1/placeholder HTTP/1.1
Showing the structure of the 'resp' object with str(resp)
List of 7
$ url : chr "https://api.dummy.gov/destiny/v1/placeholder"
$ method : NULL
$ headers :List of 4
..$ param1 : chr "10"
..$ api_key : chr "abcdefg"
..$ param2 : chr "xyz"
..$ param3 : chr "09/10/2022"
$ body : NULL
$ fields : list()
$ options : list()
$ policies: list()
- attr(*, "class")= chr "httr2_request"
Sending the request with resp %>% req_perform(verbosity = 2) gives me this error:
HTTP/1.1 403 Forbidden
---
"error":
"code": "API_KEY_MISSING",
"message": "No api_key was supplied. Please submit with a valid API key."
But when I use httr though, I can pull data from the API.
gov_url <- "https://api.dummy.gov/destiny/v1/placeholder"
query_params <- list('param1' = '10',
'api_key' = "abcdefg",
'param2' = 'xyz',
'param3' = '09/10/2022')
gov_api <- GET(path, query = query_params)
Showing structure str(gov_api) shows the path has changed which is quite good because it matches the example input provided from the API
List of 10
$ url : chr "https://api.dummy.gov/destiny/v1/placeholder?param1=10&api_key=abcdefg&param2"| __trunc
$ status_code: int 200
$ headers :List of 19
..$ xyz : chr "1"
..$ abc : chr "application/json"
..$ edg : chr "something"
And http_status(gov_api) shows its making the connection
$message
"Success: (200) OK"
Then I'm able to successfully use httr to pull data from the API.
Thank you to anyone who has read this far. I'd appreciate any feedback if possible.
Other things I've tried to no avail:
!!! to evaluate the list of expressions
Sending the API a list named queue like I do in httr
Sending the param "accept" = "application/json"
Different syntax, quotations
I'm not sure what you're after, but if you want to reproduce same comportement as httr with httr2 you can do :
library(httr2)
gov_url <- "https://api.dummy.gov/aaa/bb/cc"
param <- list(param1 = "10",
api_key = "abcdefg",
param2 = "xyz",
param3 = "09/10/2022")
resp <- request(gov_url) %>%
req_url_query(!!!param)
resp$url
#> [1] "https://api.dummy.gov/aaa/bb/cc?param1=10&api_key=abcdefg&param2=xyz&param3=09%2F10%2F2022"
Perhaps the confusion come from the fact that in httr2 you're setting headers and in httr you're setting query.

Get user detail from rstudio connect published shiny app into app.R code [duplicate]

I want to get User's IP, User's window ID and User's Server Access time
I can get User's IP with below code but Other things can't get....
getting User's IP code is
ip <- session$request$REMOTE_ADDR at server.R
How to get User's window ID and User's Server Access time ????
Long-story-short, there is a limit to what "you" (the app and therefore you, the dev) can know about the connection. I've put in similar requests for some more with RStudio professional support, and what I have below is the current capability. I hope (with no advertised timeline) that more will eventually be available.
I have RStudio Connect, which is technically a different product but similar underlying methods and I believe a lot of shared code.
Here's a shiny app that helps you "discover" things from session. I filter out most of the environment-like variables in session that are either packed full of functions or just not something useful. It's possible I've filtered out too much, you might want to play with it to see if there is more.
library(shiny)
ui <- bootstrapPage(
h3("Parsed query string"),
verbatimTextOutput("queryText"),
h3("URL components"),
verbatimTextOutput("sessionText"),
h3("EnvVars"),
verbatimTextOutput("envvarText")
)
server <- function(input, output, session) {
# Parse the GET query string
output$queryText <- renderText({
query <- parseQueryString(session$clientData$url_search)
# Return a string with key-value pairs
paste(names(query), query, sep = "=", collapse=", ")
})
# Return the components of the URL in a string:
output$sessionText <- renderText({
cls <- sapply(session, function(a) class(a)[1])
nms <- names(cls[ cls %in% c("list", "character", "numeric", "integer",
"NULL", "logical", "environment", "reactivevalues" ) ])
nms <- setdiff(nms, ".__enclos_env__")
paste(
capture.output(
str(
sapply(nms,
function(sessnm) {
if (inherits(session[[sessnm]], c("environment", "reactivevalues"))) {
sapply(names(session[[sessnm]]), function(nm) session[[sessnm]][[nm]], simplify = FALSE)
} else if (inherits(session[[sessnm]], c("character", "numeric", "integer"))) {
session[[sessnm]]
} else class(session[[sessnm]])
}, simplify = FALSE),
nchar.max = 1e5,
vec.len = 1e5
)
),
collapse = "\n"
)
})
# Dump the environment variables
output$envvarText <- renderText({
paste(
capture.output(
str(as.list(Sys.getenv()))
),
collapse = "\n"
)
})
}
shinyApp(ui, server)
Here's some sample output, cleansed for private information. (Context for this output: I changed the server's IP address to be 111.222.333.444, otherwise that should be the external IP address. Also, this is behind an nginx reverse proxy for a few reasons, so REMOTE_ADDR (for instance) is not very exciting ... but it normally might be for you.)
List of 10
$ groups : chr [1:45] "Admins" "Analytics" "Synology Desktop"
$ user : chr "r2evans"
$ userData : Named list()
$ singletons : chr(0)
$ request :List of 24
..$ HTTP_UPGRADE : chr "websocket"
..$ HTTP_CONNECTION : chr "Upgrade"
..$ HTTP_GUID : chr "_6433vf0"
..$ QUERY_STRING : chr ""
..$ httpuv.version :Classes 'package_version', 'numeric_version' hidden list of 1
.. ..$ : int [1:3] 1 5 2
..$ SERVER_NAME : chr "127.0.0.1"
..$ SCRIPT_NAME : chr ""
..$ SERVER_PORT : chr "40386"
..$ REMOTE_PORT : chr "52858"
..$ HTTP_SEC_WEBSOCKET_VERSION : chr "13"
..$ rook.input :Classes 'NullInputStream', 'R6' <NullInputStream>
Public:
close: function ()
read: function (l = -1L)
read_lines: function (n = -1L)
rewind: function ()
..$ PATH_INFO : chr "/websocket/"
..$ rook.version : chr "1.1-0"
..$ rook.errors :Classes 'ErrorStream', 'R6' <ErrorStream>
Public:
cat: function (..., sep = " ", fill = FALSE, labels = NULL)
flush: function ()
..$ HTTP_X_FORWARDED_FOR : chr "111.222.333.444:61928, ::1"
..$ HTTP_SHINY_SERVER_CREDENTIALS: chr "{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}"
..$ HTTP_SEC_WEBSOCKET_KEY : chr "NbavAciNEKYiS1AN/NGlVQ=="
..$ HTTP_SHINY_SHARED_SECRET : chr "65567ccb5db3d2990df150611eb022f4"
..$ REMOTE_ADDR : chr "127.0.0.1"
..$ HEADERS : Named chr [1:10] "Upgrade" "_6433vf0" "127.0.0.1:40386" "NbavAciNEKYiS1AN/NGlVQ==" "13" "{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}" "65567ccb5db3d2990df150611eb022f4" "websocket" "Go-http-client/1.1" "111.222.333.444!:61928, ::1"
.. ..- attr(*, "names")= chr [1:10] "connection" "guid" "host" "sec-websocket-key" "sec-websocket-version" "shiny-server-credentials" "shiny-shared-secret" "upgrade" "user-agent" "x-forwarded-for"
..$ rook.url_scheme : chr "http"
..$ REQUEST_METHOD : chr "GET"
..$ HTTP_USER_AGENT : chr "Go-http-client/1.1"
..$ HTTP_HOST : chr "127.0.0.1:40386"
$ closed : chr "logical"
$ token : chr "3a358fb6a0d42c688ea8693b67d448cb"
$ clientData :List of 13
..$ output_queryText_hidden : logi FALSE
..$ output_sessionText_hidden: logi FALSE
..$ output_envvarText_hidden : logi FALSE
..$ url_search : chr ""
..$ url_hash_initial : chr ""
..$ singletons : chr ""
..$ url_protocol : chr "https:"
..$ allowDataUriScheme : logi TRUE
..$ url_port : chr ""
..$ url_hostname : chr "server.mydomain.com"
..$ pixelratio : int 2
..$ url_hash : chr ""
..$ url_pathname : chr "/content/23/"
$ input : Named list()
$ progressStack:List of 10
..$ .__enclos_env__:<environment: 0x652f8e8>
..$ clone :function (deep = FALSE)
..$ as_list :function ()
..$ size :function ()
..$ peek :function ()
..$ pop :function ()
..$ push :function (..., .list = NULL)
..$ initialize :function (init = 20L)
..$ private :<environment: 0x652fbc0>
..$ self :<environment: 0x652f8e8>
And the environment variables:
List of 42
$ EDITOR : chr "vi"
$ HOME : chr "/home"
$ LANG : chr "en_US.UTF-8"
$ LD_LIBRARY_PATH : chr "/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/default-java/jre/lib/amd64/server"
$ LN_S : chr "ln -s"
$ LOGNAME : chr "rstudio-connect"
$ MAKE : chr "make"
$ PAGER : chr "/usr/bin/pager"
$ PATH : chr "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/rstudio-connect/ext/pandoc2"
$ PWD : chr "/opt/rstudio-connect/mnt/app"
$ R_ARCH : chr ""
$ R_BROWSER : chr "xdg-open"
$ R_BZIPCMD : chr "/bin/bzip2"
$ R_CONFIG_ACTIVE : chr "rsconnect"
$ R_DOC_DIR : chr "/usr/share/R/doc"
$ R_GZIPCMD : chr "/bin/gzip -n"
$ R_HOME : chr "/usr/lib/R"
$ R_INCLUDE_DIR : chr "/usr/share/R/include"
$ R_LIBS : chr "/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/3.5.3:"
$ R_LIBS_SITE : chr "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
$ R_LIBS_USER : chr "~/R/x86_64-pc-linux-gnu-library/3.5"
$ R_PAPERSIZE : chr "letter"
$ R_PAPERSIZE_USER : chr "letter"
$ R_PDFVIEWER : chr "/usr/bin/xdg-open"
$ R_PLATFORM : chr "x86_64-pc-linux-gnu"
$ R_PRINTCMD : chr "/usr/bin/lpr"
$ R_RD4PDF : chr "times,inconsolata,hyper"
$ R_SESSION_TMPDIR : chr "/opt/rstudio-connect/mnt/tmp/Rtmp3WkNTY"
$ R_SHARE_DIR : chr "/usr/share/R/share"
$ RSTUDIO_PANDOC : chr "/opt/rstudio-connect/ext/pandoc2"
$ R_SYSTEM_ABI : chr "linux,gcc,gxx,gfortran,?"
$ R_TEXI2DVICMD : chr "/usr/bin/texi2dvi"
$ R_UNZIPCMD : chr "/usr/bin/unzip"
$ R_ZIPCMD : chr "/usr/bin/zip"
$ SED : chr "/bin/sed"
$ SHINY_PORT : chr "40386"
$ SHINY_SERVER_VERSION: chr "1.8.2-10"
$ SHLVL : chr "0"
$ TAR : chr "/bin/tar"
$ TMPDIR : chr "/opt/rstudio-connect/mnt/tmp"
$ USER : chr "rstudio-connect"
$ USERNAME : chr "rstudio-connect"
Ultimately, publish this app, visit it, and see what you find one your instance.
Not requested, but included for completeness: here's an equivalent plumber API hit:
library(jsonlite)
library(plumber)
#* #get /clientdata
function(req, res){
classes <- sapply(req, function(a) head(class(a), n=1))
classes <- classes[! classes %in% c("ErrorStream", "NullInputStream") ]
classes <- classes[ ! names(classes) %in% c("args", "httpuv.version") ]
lapply(setNames(nm=names(classes)), function(nm) req[[nm]])
}
With output:
{
"SERVER_NAME": [
"127.0.0.1"
],
"HTTP_X_FORWARDED_FOR": [
"111.222.333.555:54590, 127.0.0.1"
],
"HTTP_ACCEPT": [
"application/json"
],
"HTTP_DNT": [
"1"
],
"SERVER_PORT": [
"33632"
],
"rook.url_scheme": [
"http"
],
"REQUEST_METHOD": [
"GET"
],
"HTTP_X_ARR_LOG_ID": [
"e5bdaca6-dcd7-4ca0-87d5-0d54927244b5"
],
"rook.version": [
"1.1-0"
],
"HTTP_X_ARR_SSL": [
"..., CN=*.mydomain.com"
],
"postBody": [],
"HTTP_RSTUDIO_CONNECT_CREDENTIALS": [
"{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}"
],
"HTTP_USER_AGENT": [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0"
],
"SCRIPT_NAME": [
""
],
"cookies": [],
"HTTP_ACCEPT_LANGUAGE": [
"en-US,en;q=0.5"
],
"HTTP_PLUMBER_SHARED_SECRET": [
"..."
],
"HTTP_REFERER": [
"https://server.mydomain.com/content/28/__swagger__/"
],
"REMOTE_PORT": [
"48684"
],
"HTTP_ACCEPT_ENCODING": [
"gzip, deflate, br"
],
"HTTP_MAX_FORWARDS": [
"10"
],
"HTTP_X_ORIGINAL_URL": [
"/content/28/clientdata"
],
"HTTP_HOST": [
"127.0.0.1:33632"
],
"HEADERS": [
"application/json",
"gzip, deflate, br",
"en-US,en;q=0.5",
"1",
"127.0.0.1:33632",
"10",
"...",
"https://server.mydomain.com/content/28/__swagger__/",
"https://server.mydomain.com/content/28",
"{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0",
"e5bdaca6-dcd7-4ca0-87d5-0d54927244b5",
"..., CN=*.mydomain.com",
"111.222.333.555:54590, 127.0.0.1",
"/content/28/clientdata",
"https://server.mydomain.com:443/content/28/clientdata"
],
"HTTP_X_RSC_REQUEST": [
"https://server.mydomain.com:443/content/28/clientdata"
],
"HTTP_RSTUDIO_CONNECT_APP_BASE_URL": [
"https://server.mydomain.com/content/28"
],
"PATH_INFO": [
"/clientdata"
],
"QUERY_STRING": [
""
],
"REMOTE_ADDR": [
"127.0.0.1"
]
}

How to get User's Information in Rshiny

I want to get User's IP, User's window ID and User's Server Access time
I can get User's IP with below code but Other things can't get....
getting User's IP code is
ip <- session$request$REMOTE_ADDR at server.R
How to get User's window ID and User's Server Access time ????
Long-story-short, there is a limit to what "you" (the app and therefore you, the dev) can know about the connection. I've put in similar requests for some more with RStudio professional support, and what I have below is the current capability. I hope (with no advertised timeline) that more will eventually be available.
I have RStudio Connect, which is technically a different product but similar underlying methods and I believe a lot of shared code.
Here's a shiny app that helps you "discover" things from session. I filter out most of the environment-like variables in session that are either packed full of functions or just not something useful. It's possible I've filtered out too much, you might want to play with it to see if there is more.
library(shiny)
ui <- bootstrapPage(
h3("Parsed query string"),
verbatimTextOutput("queryText"),
h3("URL components"),
verbatimTextOutput("sessionText"),
h3("EnvVars"),
verbatimTextOutput("envvarText")
)
server <- function(input, output, session) {
# Parse the GET query string
output$queryText <- renderText({
query <- parseQueryString(session$clientData$url_search)
# Return a string with key-value pairs
paste(names(query), query, sep = "=", collapse=", ")
})
# Return the components of the URL in a string:
output$sessionText <- renderText({
cls <- sapply(session, function(a) class(a)[1])
nms <- names(cls[ cls %in% c("list", "character", "numeric", "integer",
"NULL", "logical", "environment", "reactivevalues" ) ])
nms <- setdiff(nms, ".__enclos_env__")
paste(
capture.output(
str(
sapply(nms,
function(sessnm) {
if (inherits(session[[sessnm]], c("environment", "reactivevalues"))) {
sapply(names(session[[sessnm]]), function(nm) session[[sessnm]][[nm]], simplify = FALSE)
} else if (inherits(session[[sessnm]], c("character", "numeric", "integer"))) {
session[[sessnm]]
} else class(session[[sessnm]])
}, simplify = FALSE),
nchar.max = 1e5,
vec.len = 1e5
)
),
collapse = "\n"
)
})
# Dump the environment variables
output$envvarText <- renderText({
paste(
capture.output(
str(as.list(Sys.getenv()))
),
collapse = "\n"
)
})
}
shinyApp(ui, server)
Here's some sample output, cleansed for private information. (Context for this output: I changed the server's IP address to be 111.222.333.444, otherwise that should be the external IP address. Also, this is behind an nginx reverse proxy for a few reasons, so REMOTE_ADDR (for instance) is not very exciting ... but it normally might be for you.)
List of 10
$ groups : chr [1:45] "Admins" "Analytics" "Synology Desktop"
$ user : chr "r2evans"
$ userData : Named list()
$ singletons : chr(0)
$ request :List of 24
..$ HTTP_UPGRADE : chr "websocket"
..$ HTTP_CONNECTION : chr "Upgrade"
..$ HTTP_GUID : chr "_6433vf0"
..$ QUERY_STRING : chr ""
..$ httpuv.version :Classes 'package_version', 'numeric_version' hidden list of 1
.. ..$ : int [1:3] 1 5 2
..$ SERVER_NAME : chr "127.0.0.1"
..$ SCRIPT_NAME : chr ""
..$ SERVER_PORT : chr "40386"
..$ REMOTE_PORT : chr "52858"
..$ HTTP_SEC_WEBSOCKET_VERSION : chr "13"
..$ rook.input :Classes 'NullInputStream', 'R6' <NullInputStream>
Public:
close: function ()
read: function (l = -1L)
read_lines: function (n = -1L)
rewind: function ()
..$ PATH_INFO : chr "/websocket/"
..$ rook.version : chr "1.1-0"
..$ rook.errors :Classes 'ErrorStream', 'R6' <ErrorStream>
Public:
cat: function (..., sep = " ", fill = FALSE, labels = NULL)
flush: function ()
..$ HTTP_X_FORWARDED_FOR : chr "111.222.333.444:61928, ::1"
..$ HTTP_SHINY_SERVER_CREDENTIALS: chr "{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}"
..$ HTTP_SEC_WEBSOCKET_KEY : chr "NbavAciNEKYiS1AN/NGlVQ=="
..$ HTTP_SHINY_SHARED_SECRET : chr "65567ccb5db3d2990df150611eb022f4"
..$ REMOTE_ADDR : chr "127.0.0.1"
..$ HEADERS : Named chr [1:10] "Upgrade" "_6433vf0" "127.0.0.1:40386" "NbavAciNEKYiS1AN/NGlVQ==" "13" "{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}" "65567ccb5db3d2990df150611eb022f4" "websocket" "Go-http-client/1.1" "111.222.333.444!:61928, ::1"
.. ..- attr(*, "names")= chr [1:10] "connection" "guid" "host" "sec-websocket-key" "sec-websocket-version" "shiny-server-credentials" "shiny-shared-secret" "upgrade" "user-agent" "x-forwarded-for"
..$ rook.url_scheme : chr "http"
..$ REQUEST_METHOD : chr "GET"
..$ HTTP_USER_AGENT : chr "Go-http-client/1.1"
..$ HTTP_HOST : chr "127.0.0.1:40386"
$ closed : chr "logical"
$ token : chr "3a358fb6a0d42c688ea8693b67d448cb"
$ clientData :List of 13
..$ output_queryText_hidden : logi FALSE
..$ output_sessionText_hidden: logi FALSE
..$ output_envvarText_hidden : logi FALSE
..$ url_search : chr ""
..$ url_hash_initial : chr ""
..$ singletons : chr ""
..$ url_protocol : chr "https:"
..$ allowDataUriScheme : logi TRUE
..$ url_port : chr ""
..$ url_hostname : chr "server.mydomain.com"
..$ pixelratio : int 2
..$ url_hash : chr ""
..$ url_pathname : chr "/content/23/"
$ input : Named list()
$ progressStack:List of 10
..$ .__enclos_env__:<environment: 0x652f8e8>
..$ clone :function (deep = FALSE)
..$ as_list :function ()
..$ size :function ()
..$ peek :function ()
..$ pop :function ()
..$ push :function (..., .list = NULL)
..$ initialize :function (init = 20L)
..$ private :<environment: 0x652fbc0>
..$ self :<environment: 0x652f8e8>
And the environment variables:
List of 42
$ EDITOR : chr "vi"
$ HOME : chr "/home"
$ LANG : chr "en_US.UTF-8"
$ LD_LIBRARY_PATH : chr "/usr/lib/R/lib:/usr/lib/x86_64-linux-gnu:/usr/lib/jvm/default-java/jre/lib/amd64/server"
$ LN_S : chr "ln -s"
$ LOGNAME : chr "rstudio-connect"
$ MAKE : chr "make"
$ PAGER : chr "/usr/bin/pager"
$ PATH : chr "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/rstudio-connect/ext/pandoc2"
$ PWD : chr "/opt/rstudio-connect/mnt/app"
$ R_ARCH : chr ""
$ R_BROWSER : chr "xdg-open"
$ R_BZIPCMD : chr "/bin/bzip2"
$ R_CONFIG_ACTIVE : chr "rsconnect"
$ R_DOC_DIR : chr "/usr/share/R/doc"
$ R_GZIPCMD : chr "/bin/gzip -n"
$ R_HOME : chr "/usr/lib/R"
$ R_INCLUDE_DIR : chr "/usr/share/R/include"
$ R_LIBS : chr "/opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/3.5.3:"
$ R_LIBS_SITE : chr "/usr/local/lib/R/site-library:/usr/lib/R/site-library:/usr/lib/R/library"
$ R_LIBS_USER : chr "~/R/x86_64-pc-linux-gnu-library/3.5"
$ R_PAPERSIZE : chr "letter"
$ R_PAPERSIZE_USER : chr "letter"
$ R_PDFVIEWER : chr "/usr/bin/xdg-open"
$ R_PLATFORM : chr "x86_64-pc-linux-gnu"
$ R_PRINTCMD : chr "/usr/bin/lpr"
$ R_RD4PDF : chr "times,inconsolata,hyper"
$ R_SESSION_TMPDIR : chr "/opt/rstudio-connect/mnt/tmp/Rtmp3WkNTY"
$ R_SHARE_DIR : chr "/usr/share/R/share"
$ RSTUDIO_PANDOC : chr "/opt/rstudio-connect/ext/pandoc2"
$ R_SYSTEM_ABI : chr "linux,gcc,gxx,gfortran,?"
$ R_TEXI2DVICMD : chr "/usr/bin/texi2dvi"
$ R_UNZIPCMD : chr "/usr/bin/unzip"
$ R_ZIPCMD : chr "/usr/bin/zip"
$ SED : chr "/bin/sed"
$ SHINY_PORT : chr "40386"
$ SHINY_SERVER_VERSION: chr "1.8.2-10"
$ SHLVL : chr "0"
$ TAR : chr "/bin/tar"
$ TMPDIR : chr "/opt/rstudio-connect/mnt/tmp"
$ USER : chr "rstudio-connect"
$ USERNAME : chr "rstudio-connect"
Ultimately, publish this app, visit it, and see what you find one your instance.
Not requested, but included for completeness: here's an equivalent plumber API hit:
library(jsonlite)
library(plumber)
#* #get /clientdata
function(req, res){
classes <- sapply(req, function(a) head(class(a), n=1))
classes <- classes[! classes %in% c("ErrorStream", "NullInputStream") ]
classes <- classes[ ! names(classes) %in% c("args", "httpuv.version") ]
lapply(setNames(nm=names(classes)), function(nm) req[[nm]])
}
With output:
{
"SERVER_NAME": [
"127.0.0.1"
],
"HTTP_X_FORWARDED_FOR": [
"111.222.333.555:54590, 127.0.0.1"
],
"HTTP_ACCEPT": [
"application/json"
],
"HTTP_DNT": [
"1"
],
"SERVER_PORT": [
"33632"
],
"rook.url_scheme": [
"http"
],
"REQUEST_METHOD": [
"GET"
],
"HTTP_X_ARR_LOG_ID": [
"e5bdaca6-dcd7-4ca0-87d5-0d54927244b5"
],
"rook.version": [
"1.1-0"
],
"HTTP_X_ARR_SSL": [
"..., CN=*.mydomain.com"
],
"postBody": [],
"HTTP_RSTUDIO_CONNECT_CREDENTIALS": [
"{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}"
],
"HTTP_USER_AGENT": [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0"
],
"SCRIPT_NAME": [
""
],
"cookies": [],
"HTTP_ACCEPT_LANGUAGE": [
"en-US,en;q=0.5"
],
"HTTP_PLUMBER_SHARED_SECRET": [
"..."
],
"HTTP_REFERER": [
"https://server.mydomain.com/content/28/__swagger__/"
],
"REMOTE_PORT": [
"48684"
],
"HTTP_ACCEPT_ENCODING": [
"gzip, deflate, br"
],
"HTTP_MAX_FORWARDS": [
"10"
],
"HTTP_X_ORIGINAL_URL": [
"/content/28/clientdata"
],
"HTTP_HOST": [
"127.0.0.1:33632"
],
"HEADERS": [
"application/json",
"gzip, deflate, br",
"en-US,en;q=0.5",
"1",
"127.0.0.1:33632",
"10",
"...",
"https://server.mydomain.com/content/28/__swagger__/",
"https://server.mydomain.com/content/28",
"{\"user\":\"r2evans\",\"groups\":[\"Admins\",\"Analytics\",\"Synology Desktop\"]}",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0",
"e5bdaca6-dcd7-4ca0-87d5-0d54927244b5",
"..., CN=*.mydomain.com",
"111.222.333.555:54590, 127.0.0.1",
"/content/28/clientdata",
"https://server.mydomain.com:443/content/28/clientdata"
],
"HTTP_X_RSC_REQUEST": [
"https://server.mydomain.com:443/content/28/clientdata"
],
"HTTP_RSTUDIO_CONNECT_APP_BASE_URL": [
"https://server.mydomain.com/content/28"
],
"PATH_INFO": [
"/clientdata"
],
"QUERY_STRING": [
""
],
"REMOTE_ADDR": [
"127.0.0.1"
]
}

First argument is not an open RODBC channel

I am connecting to an Oracle database via DNS (set up the connection on the tnsnames.ora with the name "database").
I am able to succesfully run the following code:
con <- DBI::dbConnect(odbc::odbc(),
"database",
UID = "user",
PWD = "password",
trusted_connection = TRUE)
I am also able to succesfully list all the tables in the database via:
list <- dbListTables(con)
View(list)
However, when I run:
results <- sqlQuery(channel = con, query = "select * from myschemaname.table")
I get the error:
Error in sqlQuery(channel = con, query = "select * from myschemaname.table") :
first argument is not an open RODBC channel
I have owner privileges and I am also able to update Excel Spreadsheets connected to this database via ODBC.
If it's of any use, here's the output of str(con)
str(con)
Formal class 'Oracle' [package ".GlobalEnv"] with 4 slots
..# ptr :<externalptr>
..# quote : chr "\""
..# info :List of 13
.. ..$ dbname : chr ""
.. ..$ dbms.name : chr "Oracle"
.. ..$ db.version : chr "11.02.0040"
.. ..$ username : chr "user"
.. ..$ host : chr ""
.. ..$ port : chr ""
.. ..$ sourcename : chr "database"
.. ..$ servername : chr "database"
.. ..$ drivername : chr "SQORA32.DLL"
.. ..$ odbc.version : chr "03.80.0000"
.. ..$ driver.version : chr "11.02.0001"
.. ..$ odbcdriver.version : chr "03.52"
.. ..$ supports.transactions: logi TRUE
.. ..- attr(*, "class")= chr [1:3] "Oracle" "driver_info" "list"
..# encoding: chr ""
You are using RODBC::sqlQuery() for a connection created with DBI::dbConnect(). Either use DBI::dbGetQuery() with DBI::dbConnect() or create a connection with RODBC::odbcConnect(), and use RODBC::sqlQuery().
Another context, but the same error:
If the table of your DB consists of numerics, you first of all have to load an object (nameofyourtable) of class xts:
>library(RODBC)
>library(DMwR)
>library(xts)
>data(nameofyourtable)
So I had something like this connecting to a SQL Server database. In the end I had to change the Trusted_Connection=TRUE to Trusted_Connection=Yes...

What does "hidden list" in the output of `str()` mean?

In attempting to Answer this Question I came across this in the output of str()
## R reference
rref <- bibentry(bibtype = "Manual",
title = "R: A Language and Environment for Statistical Computing",
author = person("R Development Core Team"),
organization = "R Foundation for Statistical Computing",
address = "Vienna, Austria",
year = 2010,
isbn = "3-900051-07-0",
url = "http://www.R-project.org/")
> str(rref)
Class 'bibentry' hidden list of 1
$ :List of 7
..$ title : chr "R: A Language and Environment for Statistical Computing"
..$ author :Class 'person' hidden list of 1
.. ..$ :List of 5
.. .. ..$ given : chr "R Development Core Team"
.. .. ..$ family : NULL
.. .. ..$ role : NULL
.. .. ..$ email : NULL
.. .. ..$ comment: NULL
..$ organization: chr "R Foundation for Statistical Computing"
..$ address : chr "Vienna, Austria"
..$ year : chr "2010"
..$ isbn : chr "3-900051-07-0"
..$ url : chr "http://www.R-project.org/"
..- attr(*, "bibtype")= chr "Manual"
In particular, I'm puzzled by this bit:
> str(rref)
Class 'bibentry' hidden list of 1
$ :List of 7
What does the "hidden list" bit refer to? What kind of object is this? Is this just some formatting output from str() when there is only a single component in the object that is itself a list? If so how is there a way to force str() to show the full structure?
This seems like an artefact of str. My interpretation is that the words hidden list are printed in the output of str if the obect is not a pairlist.
Since your object is of class bibtex, and there is no str method for bibtex, the method utils:::str.default is used to describe the structure.
Condensed extract from str.default:
...
if (is.list(object)) {
i.pl <- is.pairlist(object)
...
cat(if (i.pl)
"Dotted pair list"
else if (irregCl)
paste(pClass(cl), "hidden list")
else "List", " of ", le, "\n", sep = "")
...
}
The key bit that defines irregCl is:
....
else {
if (irregCl <- has.class && identical(object[[1L]],
object)) {
....
and that explain the hidden list bit - it hides the outer list if the object has a class and object and object[[1]] are identical. As you showed in the Answer you linked to, the [[ method returns an identical object if the list contains a single "bibentry" object.

Resources