I have the following code that I've create to make up the documentation, and function for an API. I'm having issues when I use write
with the code. The third line of the code ends up adding in question marks.
Example:
test_function <- structure(c("#' Add/Drops", "#'", "#' Retrieve a list of add/drops for the owner’s team. The list will include the following.",
"#'", "#' @export", "#' @importFrom httr POST GET add_headers content warn_for_status",
"#' @importFrom jsonlite fromJSON", "add_drops <- function() {",
" params <- list(", " response_format = \"JSON\",", " version = \"3.0\",",
" access_token = cbs_token", " )", "", " params <- no_null(params)",
" res <- httr::GET(", " url = \"http://api.cbssports.com/fantasy/league/transaction-list/add-drops\",",
" query = params", " )", "", " warn_for_status(res)", " jsonlite::fromJSON(httr::content(res, \"text\", encoding = \"UTF-8\"), flatten = TRUE)",
"}"), class = "vertical")
test_function
#' Add/Drops
#'
#' Retrieve a list of add/drops for the owner’s team. The list will include the following.
#'
#' @export
#' @importFrom httr POST GET add_headers content warn_for_status
#' @importFrom jsonlite fromJSON
add_drops <- function() {
params <- list(
response_format = "JSON",
version = "3.0",
access_token = cbs_token
)
params <- no_null(params)
res <- httr::GET(
url = "http://api.cbssports.com/fantasy/league/transaction-list/add-drops",
query = params
)
warn_for_status(res)
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), flatten = TRUE)
}
The following code above looks exactly as I want it to look for the .R
file.
Now, the issue happens when I use write
title <- "test_function"
write(test_function, sprintf("R/%s.R", title))
#' Add/Drops
#'
#' Retrieve a list of add/drops for the owner?s team. The list will include the following.
#'
#' @export
#' @importFrom httr POST GET add_headers content warn_for_status
#' @importFrom jsonlite fromJSON
add_drops <- function() {
params <- list(
response_format = "JSON",
version = "3.0",
access_token = cbs_token
)
params <- no_null(params)
res <- httr::GET(
url = "http://api.cbssports.com/fantasy/league/transaction-list/add-drops",
query = params
)
warn_for_status(res)
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), flatten = TRUE)
}
For some reason a ? replaces the ' in the word "owner's". Initially I thought it had to do with the ', but I get the same issue without a '.
Example 2:
test_function2 <- structure(c("#' Sports", "#'", "#' A list of the official CBS Interacive ID codes for sports. These are the sport IDs that must be used when requesting any FOPE API resource that requires the SPORT parameter. The resource contains a list of all the pro sports for which CBS Interactive a fantasy sports program. For each sport, it provides the offical CBS Interactive ID for the sport, a common English name for the sport, and an abbreviation for the sport.",
"#'", "#' @export", "#' @importFrom httr POST GET add_headers content warn_for_status",
"#' @importFrom jsonlite fromJSON", "sports <- function() {",
" params <- list(", " response_format = \"JSON\",", " version = \"3.0\",",
" access_token = cbs_token", " )", "", " params <- no_null(params)",
" res <- httr::GET(", " url = \"http://api.cbssports.com/fantasy/sports\",",
" query = params", " )", "", " warn_for_status(res)", " jsonlite::fromJSON(httr::content(res, \"text\", encoding = \"UTF-8\"), flatten = TRUE)",
"}"), class = "vertical")
test_function 2
#' Sports
#'
#' A list of the official CBS Interacive ID codes for sports. These are the sport IDs that must be used when requesting any FOPE API resource that requires the SPORT parameter. The resource contains a list of all the pro sports for which CBS Interactive a fantasy sports program. For each sport, it provides the offical CBS Interactive ID for the sport, a common English name for the sport, and an abbreviation for the sport.
#'
#' @export
#' @importFrom httr POST GET add_headers content warn_for_status
#' @importFrom jsonlite fromJSON
sports <- function() {
params <- list(
response_format = "JSON",
version = "3.0",
access_token = cbs_token
)
params <- no_null(params)
res <- httr::GET(
url = "http://api.cbssports.com/fantasy/sports",
query = params
)
warn_for_status(res)
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), flatten = TRUE)
}
Here is what that .R
file looks like.
#' Sports
#'
#' A list of the official CBS Interacive ID codes for sports.? These are the sport IDs that must be used when requesting any FOPE API resource that requires the SPORT parameter.? The resource contains a list of all the pro sports for which CBS Interactive a fantasy sports program.? For each sport, it provides the offical CBS Interactive ID for the sport, a common English name for the sport, and an abbreviation for the sport.
#'
#' @export
#' @importFrom httr POST GET add_headers content warn_for_status
#' @importFrom jsonlite fromJSON
sports <- function() {
params <- list(
response_format = "JSON",
version = "3.0",
access_token = cbs_token
)
params <- no_null(params)
res <- httr::GET(
url = "http://api.cbssports.com/fantasy/sports",
query = params
)
warn_for_status(res)
jsonlite::fromJSON(httr::content(res, "text", encoding = "UTF-8"), flatten = TRUE)
}
Any idea why this would be happening, or how to fix it?