I am trying to compile the PDF version of Efficient R Programming using RStudio on my Windows 7 machine. Using the instructions here I was able to compile the HTML version, but the code for the PDF version fails. After running the code below (which seems to work at first), I got the warning messages below:
## For pdf
bookdown::render_book("index.Rmd", output_format = bookdown::pdf_book())
output file: _main.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output _main.tex --table-of-contents --toc-depth 2 --template "C:\R\R-3.4.4\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" --variable tables=yes --standalone --filter pandoc-citeproc
Error: Failed to compile _main.tex.
In addition: Warning messages:
1: In file.remove("voc_voyages.xlsx") :
cannot remove file 'voc_voyages.xlsx', reason 'No such file or directory'
2: In connection_release(conn#ptr) :
There are 1 result in use. The connection will be released when they are closed
3: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'benchmarkme'
4: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'benchmarkme' from package DESCRIPTION file
5: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'bookdown'
6: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'bookdown' from package DESCRIPTION file
7: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'efficient'
8: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'efficient' from package DESCRIPTION file
9: running command '"pdflatex" -halt-on-error -interaction=batchmode "_main.tex"' had status 127
Please delete _main.Rmd after you finish debugging the error.
I found this discussion of MikTeX vs tinytex. I then installed tinytex and now get this (slightly different) error:
## For pdf
bookdown::render_book("index.Rmd", output_format = bookdown::pdf_book())
label: unnamed-chunk-235
ordinary text without R code
label: unnamed-chunk-236
ordinary text without R code
label: unnamed-chunk-237 (with options)
List of 1
$ message: logi FALSE
Attaching package: 'Matrix'
The following object is masked from 'package:tidyr':
expand
ordinary text without R code
label: unnamed-chunk-238
|............................................... | 73%
ordinary text without R code
label: unnamed-chunk-239 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-240 (with options)
List of 2
$ results: chr "hide"
$ indent : chr " "
ordinary text without R code
|................................................ | 73%
label: 7-4 (with options)
List of 3
$ echo : logi FALSE
$ out.width: chr "100%"
$ fig.cap : chr "Code profiling of the optimised code."
ordinary text without R code
label: unnamed-chunk-241 (with options)
List of 2
$ eval: logi FALSE
$ echo: logi FALSE
ordinary text without R code
|................................................ | 74%
label: unnamed-chunk-242 (with options)
List of 1
$ echo: language 1:2
ordinary text without R code
label: unnamed-chunk-243 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-244 (with options)
List of 2
$ eval: logi FALSE
$ tidy: logi FALSE
ordinary text without R code
label: unnamed-chunk-245 (with options)
List of 2
$ eval: logi FALSE
$ echo: language c(1, 3)
ordinary text without R code
|................................................ | 75%
label: unnamed-chunk-246 (with options)
List of 2
$ eval: logi FALSE
$ echo: language 2:3
|................................................. | 75%
ordinary text without R code
label: unnamed-chunk-247 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-248 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-249
ordinary text without R code
|................................................. | 76%
label: unnamed-chunk-250 (with options)
List of 2
$ type : chr "rmdtip"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-251 (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
label: unnamed-chunk-252 (with options)
List of 1
$ results: chr "hide"
|.................................................. | 76%
ordinary text without R code
label: 7-5 (with options)
List of 7
$ echo : logi FALSE
$ fig.cap : chr "Downloads per day from the RStudio CRAN mirror of packages that provide R interfaces to other languages."
$ warning : logi FALSE
$ fig.width : num 6
$ fig.height: num 4
$ out.width : chr "70%"
$ fig.align : chr "center"
inline R code fragments
|.................................................. | 77%
label: test_cpp (with options)
List of 2
$ eval : logi FALSE
$ results: chr "hide"
ordinary text without R code
label: unnamed-chunk-253
ordinary text without R code
label: unnamed-chunk-254 (with options)
List of 3
$ eval : logi FALSE
$ tidy : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-255 (with options)
List of 1
$ tidy: logi FALSE
ordinary text without R code
|.................................................. | 78%
label: unnamed-chunk-256
ordinary text without R code
|................................................... | 78%
label: unnamed-chunk-257
ordinary text without R code
label: unnamed-chunk-258 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
label: cpptypes (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
|................................................... | 79%
label: unnamed-chunk-259 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-260 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-261 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
|.................................................... | 79%
label: unnamed-chunk-262 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
|.................................................... | 80%
label: unnamed-chunk-263 (with options)
List of 1
$ engine: chr "Rcpp"
Building shared library for Rcpp code chunk...
ordinary text without R code
label: unnamed-chunk-264
ordinary text without R code
label: unnamed-chunk-265 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-266
ordinary text without R code
label: unnamed-chunk-267 (with options)
List of 3
$ eval : logi FALSE
$ engine: chr "Rcpp"
$ indent: chr " "
|.................................................... | 81%
ordinary text without R code
label: unnamed-chunk-268 (with options)
List of 3
$ eval : logi FALSE
$ engine: chr "Rcpp"
$ indent: chr " "
|..................................................... | 81%
ordinary text without R code
label: unnamed-chunk-269
ordinary text without R code
label: unnamed-chunk-270 (with options)
List of 3
$ cache: logi TRUE
$ echo : language -1
$ eval : logi FALSE
ordinary text without R code
label: 7-6 (with options)
List of 7
$ fig.width : num 6
$ fig.height: num 4
$ echo : num 2
$ fig.cap : chr "Comparison of mean functions."
$ cache : logi TRUE
$ fig.pos : chr "t"
$ out.width : chr "70%"
|..................................................... | 82%
ordinary text without R code
label: unnamed-chunk-271 (with options)
List of 3
$ eval : logi FALSE
$ tidy : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-272 (with options)
List of 3
$ eval : logi FALSE
$ engine: chr "Rcpp"
$ indent: chr " "
ordinary text without R code
label: unnamed-chunk-273
|...................................................... | 82%
ordinary text without R code
label: unnamed-chunk-274 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
|...................................................... | 83%
ordinary text without R code
label: unnamed-chunk-275 (with options)
List of 2
$ eval : logi FALSE
$ engine: chr "Rcpp"
ordinary text without R code
label: unnamed-chunk-276 (with options)
List of 2
$ include: logi FALSE
$ cache : logi FALSE
ordinary text without R code
label: unnamed-chunk-277 (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
label: unnamed-chunk-278
|...................................................... | 84%
ordinary text without R code
label: ascii (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
|....................................................... | 84%
label: unnamed-chunk-279 (with options)
List of 1
$ echo: num 2
ordinary text without R code
label: unnamed-chunk-280
ordinary text without R code
label: unnamed-chunk-281
|....................................................... | 85%
ordinary text without R code
label: unnamed-chunk-282 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-283 (with options)
List of 2
$ type : chr "rmdtip"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-284 (with options)
List of 1
$ results: chr "hide"
ordinary text without R code
|........................................................ | 85%
label: 8-1 (with options)
List of 3
$ fig.cap : chr "Three DIMM slots on a computer motherboard used for increasing the amount of available RAM. Credit: Wikimedia.org"
$ echo : logi FALSE
$ out.width: chr "100%"
|........................................................ | 86%
ordinary text without R code
label: unnamed-chunk-285
ordinary text without R code
label: unnamed-chunk-286
ordinary text without R code
label: unnamed-chunk-287 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
label: 8-2 (with options)
List of 2
$ fig.cap: chr "A standard 2.5\" hard drive, found in most laptops. Credit: https://en.wikipedia.org/wiki/Hard\\_disk\\_drive"
$ echo : logi FALSE
|........................................................ | 87%
ordinary text without R code
label: unnamed-chunk-288 (with options)
List of 2
$ type : chr "rmdtip"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-289 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
|......................................................... | 87%
ordinary text without R code
label: unnamed-chunk-290 (with options)
List of 1
$ results: chr "hide"
ordinary text without R code
label: 8-3 (with options)
List of 5
$ echo : logi FALSE
$ fig.width : num 6
$ fig.height: num 4
$ fig.cap : chr "CPU clock speed. The data for this figure was collected from web-forum and wikipedia. It is intended to indicat"| __truncated__
$ out.width : chr "70%"
ordinary text without R code
|......................................................... | 88%
label: 8-4 (with options)
List of 6
$ echo : logi FALSE
$ fig.width : num 6
$ fig.height: num 4
$ fig.cap : chr "CPU benchmarks from the R package, **benchmarkme**. Each point represents an individual CPU result."
$ fig.keep : chr "last"
$ out.width : chr "70%"
ordinary text without R code
label: unnamed-chunk-291 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-292 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-293 (with options)
List of 2
$ include: logi FALSE
$ cache : logi FALSE
|.......................................................... | 88%
ordinary text without R code
|.......................................................... | 89%
label: unnamed-chunk-294 (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
label: unnamed-chunk-295 (with options)
List of 2
$ echo : logi FALSE
$ message: logi FALSE
ordinary text without R code
label: unnamed-chunk-296 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-297
ordinary text without R code
|.......................................................... | 90%
label: unnamed-chunk-298
ordinary text without R code
label: unnamed-chunk-299 (with options)
List of 2
$ engine: chr "bash"
$ eval : logi FALSE
ordinary text without R code
|........................................................... | 90%
label: unnamed-chunk-300 (with options)
List of 1
$ messages: logi FALSE
ordinary text without R code
label: unnamed-chunk-301
ordinary text without R code
|........................................................... | 91%
label: unnamed-chunk-302
ordinary text without R code
label: unnamed-chunk-303 (with options)
List of 2
$ type : chr "rmdwarning"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-304 (with options)
List of 2
$ results: chr "hide"
$ message: logi FALSE
Attaching package: 'lubridate'
The following objects are masked from 'package:data.table':
hour, isoweek, mday, minute, month, quarter, second, wday,
week, yday, year
The following object is masked from 'package:base':
date
ordinary text without R code
label: unnamed-chunk-305 (with options)
List of 2
$ eval : logi FALSE
$ results: chr "hide"
ordinary text without R code
|........................................................... | 92%
label: unnamed-chunk-306 (with options)
List of 2
$ echo : language 2:5
$ results: chr "hide"
|............................................................ | 92%
ordinary text without R code
label: unnamed-chunk-307 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-308 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-309 (with options)
List of 1
$ results: chr "hide"
ordinary text without R code
|............................................................ | 93%
label: 9-1 (with options)
List of 3
$ fig.cap : chr "The Git tab in RStudio"
$ echo : logi FALSE
$ out.width: chr "70%"
ordinary text without R code
label: 9-2 (with options)
List of 3
$ fig.cap : chr "The Git history navigation interface"
$ echo : logi FALSE
$ out.width: chr "100%"
ordinary text without R code
label: unnamed-chunk-310 (with options)
List of 1
$ eval: logi FALSE
|............................................................. | 93%
ordinary text without R code
label: note-text (with options)
List of 2
$ type : chr "rmdwarning"
$ engine: chr "block"
ordinary text without R code
label: unnamed-chunk-311 (with options)
List of 2
$ engine: chr "bash"
$ eval : logi FALSE
|............................................................. | 94%
ordinary text without R code
label: unnamed-chunk-312 (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
label: unnamed-chunk-313 (with options)
List of 2
$ include: logi FALSE
$ cache : logi FALSE
ordinary text without R code
label: unnamed-chunk-314 (with options)
List of 1
$ echo: logi FALSE
ordinary text without R code
label: unnamed-chunk-315
|............................................................. | 95%
ordinary text without R code
|.............................................................. | 95%
label: unnamed-chunk-316 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-317 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-318 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-319
|.............................................................. | 96%
ordinary text without R code
label: unnamed-chunk-320 (with options)
List of 3
$ echo : logi FALSE
$ fig.cap : chr "Package name autocompletion in action in RStudio for packages beginning with 'geo'."
$ out.width: chr "100%"
ordinary text without R code
label: unnamed-chunk-321 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
ordinary text without R code
|............................................................... | 96%
label: unnamed-chunk-322 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-323 (with options)
List of 1
$ eval: logi FALSE
|............................................................... | 97%
ordinary text without R code
label: unnamed-chunk-324 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-325
ordinary text without R code
label: unnamed-chunk-326 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-327 (with options)
List of 2
$ type : chr "rmdnote"
$ engine: chr "block"
|............................................................... | 98%
ordinary text without R code
label: unnamed-chunk-328 (with options)
List of 2
$ type : chr "rmdtip"
$ engine: chr "block"
|................................................................ | 98%
ordinary text without R code
label: unnamed-chunk-329 (with options)
List of 1
$ eval: logi FALSE
ordinary text without R code
label: unnamed-chunk-330 (with options)
List of 1
$ echo: language -3
ordinary text without R code
label: unnamed-chunk-331 (with options)
List of 1
$ results: chr "hide"
|................................................................ | 99%
ordinary text without R code
label: unnamed-chunk-332 (with options)
List of 2
$ include: logi FALSE
$ cache : logi FALSE
ordinary text without R code
label: unnamed-chunk-333 (with options)
List of 2
$ eval : logi FALSE
$ indent: chr " "
ordinary text without R code
label: unnamed-chunk-334 (with options)
List of 1
$ eval: logi FALSE
|.................................................................| 99%
ordinary text without R code
label: is_travis (with options)
List of 1
$ echo: logi FALSE
|.................................................................| 100%
ordinary text without R code
label: unnamed-chunk-335 (with options)
List of 4
$ echo : logi FALSE
$ warning: logi FALSE
$ message: logi FALSE
$ eval : language, mode "(": (!is_travis)
tweaking fortunes
ordinary text without R code
label: unnamed-chunk-336 (with options)
List of 3
$ echo : logi FALSE
$ message: logi FALSE
$ warning: logi FALSE
ordinary text without R code
output file: _main.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS _main.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output _main.tex --table-of-contents --toc-depth 2 --template "C:\R\R-3.4.4\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes" --variable tables=yes --standalone --filter pandoc-citeproc
Output created: _book/_main.pdf
Error in tools::file_path_as_absolute(output_file) :
file '_book/_main.pdf' does not exist
In addition: Warning messages:
1: In file.remove("voc_voyages.xlsx") :
cannot remove file 'voc_voyages.xlsx', reason 'No such file or directory'
2: In connection_release(conn#ptr) :
There are 1 result in use. The connection will be released when they are closed
3: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'benchmarkme'
4: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'benchmarkme' from package DESCRIPTION file
5: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'bookdown'
6: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'bookdown' from package DESCRIPTION file
7: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
no date field in DESCRIPTION file of package 'efficient'
8: In citation(pkg, auto = if (pkg == "base") NULL else TRUE) :
could not determine year for 'efficient' from package DESCRIPTION file
9: running command '"pdflatex" -halt-on-error -interaction=batchmode "_main.tex"' had status 1
10: In readLines(logfile) : incomplete final line found on '_main.log'
Please delete _main.Rmd after you finish debugging the error.
Based on the comment from #jaySf below, I ran this code, but still got the same error:
remove.packages("rmarkdown")
install.packages("devtools")
library(devtools)
install_version("rmarkdown", version = "1.8")
## For pdf
bookdown::render_book("index.Rmd", output_format = bookdown::pdf_book())
Any suggestions would be appreciated. Thanks.
Related
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"
]
}
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"
]
}
There is something strange with this error. Sometimes the same rmd file with r chunks runs without problems and knitr assigns sequential number after the 'unnamed-chunk-' but sometimes knitr reports error.
I can't find any way to identify under what circumstances the process runs smoothly and when it generates error. All r chunks within rmd file are without the name/label.
Below there is the log of command in case everything is going smoothly and the not labels chunks are given sequential number
outfile = c(outfile, knit("File1.rmd"))
processing file: File1.Rmd
|..... | 8%
ordinary text without R code
|........... | 17%
label: unnamed-chunk-1 (with options)
List of 1
$ echo: logi FALSE
|................ | 25%
inline R code fragments
|...................... | 33%
label: unnamed-chunk-2 (with options)
List of 4
$ echo : logi FALSE
$ connection: symbol db.conn
$ output.var: chr "db.data"
$ engine : chr "sql"
|........................... | 42%
ordinary text without R code
|................................ | 50%
label: unnamed-chunk-3 (with options)
List of 1
$ echo: logi FALSE
|...................................... | 58%
ordinary text without R code
|........................................... | 67%
label: unnamed-chunk-4 (with options)
List of 1
$ echo: logi FALSE
|................................................. | 75%
ordinary text without R code
|...................................................... | 83%
label: unnamed-chunk-5 (with options)
List of 1
$ echo: logi FALSE
|............................................................ | 92%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-6 (with options)
List of 1
$ echo: logi FALSE
output file: Test_DSN-ARAMIS-01.md
> outfile = c(outfile, knit_child("File2.Rmd"))
processing file: File2.Rmd
|............. | 8%
ordinary text without R code
|......................... | 17%
label: unnamed-chunk-1 (with options)
List of 1
$ echo: logi FALSE
|...................................... | 25%
inline R code fragments
|.................................................. | 33%
label: unnamed-chunk-2 (with options)
List of 4
$ echo : logi FALSE
$ connection: symbol db.conn
$ output.var: chr "db.data"
$ engine : chr "sql"
|............................................................... | 42%
ordinary text without R code
|............................................................................ | 50%
label: unnamed-chunk-3 (with options)
List of 1
$ echo: logi FALSE
|........................................................................................ | 58%
ordinary text without R code
|..................................................................................................... | 67%
label: unnamed-chunk-4 (with options)
List of 1
$ echo: logi FALSE
|................................................................................................................. | 75%
ordinary text without R code
|.............................................................................................................................. | 83%
label: unnamed-chunk-5 (with options)
List of 1
$ echo: logi FALSE
|.......................................................................................................................................... | 92%
ordinary text without R code
|.......................................................................................................................................................| 100%
label: unnamed-chunk-6 (with options)
List of 1
$ echo: logi FALSE
and the second execution of the same files gives the following output when processing second file
> outfile = c(outfile, knit_child("File2.Rmd"))
processing file: File2.Rmd
Error in parse_block(g[-1], g[1], params.src) :
duplicate label 'unnamed-chunk-1'
There are 2 situations:
You could have a duplicate chunk name
You could have copied and pasted the same code over. If so do the following:
options(knitr.duplicate.label = "allow")
https://bookdown.org/yihui/rmarkdown-cookbook/duplicate-label.html
It looks like there is an explanation and solution to this exact problem give here https://bookdown.org/yihui/rmarkdown-cookbook/duplicate-label.html
options(knitr.duplicate.label = "allow")
I've tried it on my own system, when faced with the same problem, and it was resolved.
Answering this for anyone who gets a similar error:
This is probably a duplicate code block.
Check your document for a duplicate code block name, the block name is in <> in the example below:
```{r <block-name> }```
Full kudos to user cderv on rstudio for this solution.
So I am using a package in R called twitteR
consumer_key <- "MY API KEY"
consumer_secret <- "MY API KEY"
access_token <- "MY API KEY"
access_secret <- "MY API KEY"
setup_twitter_oauth(consumer_key,
consumer_secret,
access_token,
access_secret)
tweets<-searchTwitter('NASA',n=3200,lang = 'en')
Now I have list called tweets
> length(tweets)
[1] 3200
Looking at the first few elements
> tweets[1:3]
[[1]]
[1] "PepperAlbo: RT #mashable: NASA researchers reinvented the wheel"
[[2]]
[1] "UnitedStatesTD: NASA to release Voyager Golden Record as a vinyl box set - via #UnitedStatesTD "
[[3]]
[1] "ISSAboveYou: Hello #Space_Station from The Vails of Long Beach CA 302.0 mi away #NASA_Johnson #issabove "
Clearly the tweets are in lists within list, so lets say I call on the first element
> tweets[[1]]
[1] "PepperAlbo: RT #mashable: NASA researchers reinvented the wheel "
But there is actually more to the list
> str(tweets[[1]])
Reference class 'status' [package "twitteR"] with 17 fields
$ text : chr "RT #mashable: NASA researchers reinvented the wheel "
$ favorited : logi FALSE
$ favoriteCount: num 0
$ replyToSN : chr(0)
$ created : POSIXct[1:1], format: "2017-11-29 01:07:18"
$ truncated : logi FALSE
$ replyToSID : chr(0)
$ id : chr "935676507661524992"
$ replyToUID : chr(0)
$ statusSource : chr "Twitter for iPhone"
$ screenName : chr "PepperAlbo"
$ retweetCount : num 685
$ isRetweet : logi TRUE
$ retweeted : logi FALSE
$ longitude : chr(0)
$ latitude : chr(0)
$ urls :'data.frame': 0 obs. of 4 variables:
..$ url : chr(0)
..$ expanded_url: chr(0)
..$ dispaly_url : chr(0)
..$ indices : num(0)
and 53 methods, of which 39 are possibly relevant:
getCreated, getFavoriteCount, getFavorited, getId, getIsRetweet, getLatitude, getLongitude, getReplyToSID, getReplyToSN, getReplyToUID, getRetweetCount,
getRetweeted, getRetweeters, getRetweets, getScreenName, getStatusSource, getText, getTruncated, getUrls, initialize, setCreated, setFavoriteCount,
setFavorited, setId, setIsRetweet, setLatitude, setLongitude, setReplyToSID, setReplyToSN, setReplyToUID, setRetweetCount, setRetweeted, setScreenName,
setStatusSource, setText, setTruncated, setUrls, toDataFrame, toDataFrame#twitterObj
using one of them
> tweets[[1]]$id
[1] "935676507661524992"
So my question is where is all of this stored? is it along with the tweet text in the tweet[[1]]? So when I call only tweet[[1]] why is it that only the tweet gets printed and nothing else?
Is this a special kind of list that is being defined by this Reference class 'status' ?
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.