I'm building a package but the documentation must be in Spanish, including the tilde character (i.e. í, é).
I have a simple function like this in an R file:
#' Función con acénto
#'
#' Permite instalar rápidamente de manera local un paquete previamente descargado
#' #param direccion La dirección del archivo local, poner .zip
#' #keywords FAhorroDS
#' #export
#' #encoding UTF-8
#' #author Eduardo Flores
#' #examples
#' FA_InstalarLocal("paquete_x_1.10.zip")
FA_InstalarLocal<-function(direccion)
{
install.packages(direccion, repos = NULL, type="source")
}
And building the Rd via devtools::document(). The Rd file in man generated seems fine:
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/test.R
\encoding{UTF-8}
\name{FA_InstalarLocal}
\alias{FA_InstalarLocal}
\title{Función con acénto}
\usage{
FA_InstalarLocal(direccion)
}
\arguments{
\item{direccion}{La dirección del archivo local, poner .zip}
}
\description{
Permite instalar rápidamente de manera local un paquete previamente descargado
}
\examples{
FA_InstalarLocal("paquete_x_1.10.zip")
}
\author{
Eduardo Flores
}
\keyword{FAhorroDS}
However even if i'm specifying the encoding both here and in the DOCUMENTATION file, when I run: system("R CMD Rd2pdf . --output=manual.pdf --force"), I get the following error:
Hmm ... looks like a package
Converting Rd files to LaTeX Warning: ./man/FA_InstalarLocal.Rd:6: Some input could not be re-encoded to ASCII
When I see the package, the description is okay, but the title of the function turns out as NA.
Any ideas as to why everything else (the description has a tilde) is being correctly encoded but not the title?
> sessionInfo()
R version 3.2.4 Revised (2016-03-16 r70336)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Spanish_Mexico.1252 LC_CTYPE=Spanish_Mexico.1252
[3] LC_MONETARY=Spanish_Mexico.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Mexico.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] fahorro_0.1 devtools_1.10.0 magrittr_1.5 readxl_0.1.0 dplyr_0.4.3
[6] FAhorroDS_1.0.1
loaded via a namespace (and not attached):
[1] Rcpp_0.11.6 roxygen2_5.0.1 R6_2.1.2 xlsx_0.5.7 stringr_1.0.0
[6] plyr_1.8.3 tools_3.2.4 parallel_3.2.4 DBI_0.3.1 withr_1.0.0
[11] assertthat_0.1 digest_0.6.9 rJava_0.9-8 RODBC_1.3-12 xlsxjars_0.6.1
[16] memoise_1.0.0 stringi_1.0-1 SOAR_0.99-11
Related
I can't seem to manage to get the action button in shiny working. Nothing happens when i press "click me" and there is no error message.
Does anyone have a clue what might be wrong?
library(shiny)
ui <- fluidPage(
tags$head(tags$script(src = "message-handler.js")),
actionButton("do", "Click Me")
)
server <- function(input, output, session) {
observeEvent(input$do, {
session$sendCustomMessage(type = 'testmessage',
message = 'Thank you for clicking')
})
}
shinyApp(ui, server)
here is my session info:
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=Swedish_Sweden.1252 LC_CTYPE=Swedish_Sweden.1252 LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C LC_TIME=Swedish_Sweden.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_1.4.0.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 packrat_0.5.0 digest_0.6.27 later_1.1.0.1 mime_0.9 R6_2.5.0 xtable_1.8-4 jsonlite_1.7.2 magrittr_2.0.1
[10] rlang_0.4.10 promises_1.1.0 tools_3.6.3 httpuv_1.5.2 rsconnect_0.8.16 fastmap_1.0.1 compiler_3.6.3 htmltools_0.5.1.1
In my toy package, I have defined %+% operator as an alias to paste0(). Trying to reduce interference with other packages, I realized it the following way:
`%+%` <- function(...) UseMethod("%+%")
`%+%.character` <- paste0
`%+%.numeric` <- paste0
`%+%.default` <- function (arg1, arg2){
e <- parent.env(getEnvByName(.GlobalEnv,'package:mypackagename'));
if (exists('%+%', envir = e)) get('%+%',envir = e)(arg1,arg2);
}
i.e. I override it only for character and numeric arguments, otherwise it tries to find if the method was previously defined.
It was working just fine until recently when it started giving an error:
'a' %+% 'b'
# Error in UseMethod("%+%") :
# no applicable method for '%+%' applied to an object of class "character"
It only fails when called outside of the package. If I define a function within the package, it works correctly:
# testab2() is defined in R file as a part of the package:
testab2 <- function(inpA, inpB){
print (inpA %+% inpB)
}
# when called outside of the package:
testab2('a','b')
# ab
I am pretty sure I didn't change anything in my code, so I'm wondering if it could be caused by R update. What could have changed and how to make it work back?
P.S. getEnvByName() is my helper function that searches for an object in parent environments:
getEnvByName <- function(inpEnv=.GlobalEnv, lookFor){
e <- inpEnv;
while (environmentName(e) != 'R_EmptyEnv' & environmentName(e)!=lookFor) e <- parent.env(e);
if (environmentName(e) != lookFor) return(NULL);
return(e);
}
And the exporting was done by the following lines in the NAMESPACE file:
exportPattern("^[[:alpha:]]+")
exportPattern("%.*%")
export("%+%.default")
export("%+%.character")
P.P.S. sessionInfo:
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
system code page: 1251
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] vautils_0.1.1.105 magrittr_1.5 data.table_1.13.0
loaded via a namespace (and not attached):
[1] dplyr_1.0.2 crayon_1.3.4 grid_4.0.2 R6_2.4.1 lifecycle_0.2.0 gtable_0.3.0
[7] scales_1.1.1 ggplot2_3.3.2 pillar_1.4.6 rlang_0.4.7 rstudioapi_0.11 generics_0.0.2
[13] vctrs_0.3.4 ellipsis_0.3.1 tools_4.0.2 glue_1.4.2 purrr_0.3.4 munsell_0.5.0
[19] compiler_4.0.2 pkgconfig_2.0.3 colorspace_1.4-1 tidyselect_1.1.0 tibble_3.0.3
To export S3 methods, your NAMESPACE file needs to (in your case) contain the following declarations:
export(`%+%`)
S3method(`%+%`, default)
S3method(`%+%`, character)
S3method(`%+%`, numeric)
That is, export the %+% generic, and declare S3 methods for the methods.
Better yet, instead of manually editing the NAMESPACE file use ‘roxygen2’, which generates the correct declarations for you based on the #export documentation tag.
I am not able to create a twitter token using create_token from rtweet package:
library (rtweet)
twitter_token <- create_token(app = appname, # as set in Twitter API
consumer_key = key, # as set in Twitter API
consumer_secret = secret) # as set in Twitter API
The output I get is:
Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, :
Forbidden (HTTP 403).
I followed the instructions to setup Twitter API as disclosed in http://rtweet.info/articles/auth.html, and triple checked that the Callback URL was properly set as http://127.0.0.1:1410.
I also tried:
createTokenNoBrowser<- function(appName, consumerKey, consumerSecret,
accessToken, accessTokenSecret) {
app <- httr::oauth_app(appName, consumerKey, consumerSecret)
params <- list(as_header = TRUE)
credentials <- list(oauth_token = accessToken,
oauth_token_secret = accessTokenSecret)
token <- httr::Token1.0$new(endpoint = NULL, params = params,
app = app, credentials = credentials)
return(token)
}
It seems to work, but when I call
rt <- stream_tweets(q = q, file_name = filename,token = twitter_token)
I get: Error: Not a valid access token.
What might be going wrong?
I am currently using R 3.5.0. Thank you.
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 LC_MONETARY=Portuguese_Brazil.1252
[4] LC_NUMERIC=C LC_TIME=Portuguese_Brazil.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rtweet_0.6.4
loaded via a namespace (and not attached):
[1] readr_1.1.1 httr_1.3.1 compiler_3.5.0 magrittr_1.5 R6_2.2.2 hms_0.4.2 tools_3.5.0 pillar_1.2.3
[9] curl_3.2 tibble_1.4.2 yaml_2.1.19 Rcpp_0.12.17 jsonlite_1.5 openssl_1.0.1 pkgconfig_2.0.1 rlang_0.2.1
This issue has been fixed in the newest version of rtweet on Github!
I believe create_token() is deprecated in the latest version of rtweet. Instead, you should use rtweet_app() or rtweet_bot().
How can I automate the documentation of the #usage section for Rcpp functions? In an ordinary R function within a package documented using roxygen2, the Usage section is added automatically. This is convenient for automatically documenting default arguments.
#' #title Hello world
#' #return Prints 'Hello world'
#' #export
#' #useDynLib RcppSandBox
hello <- function(x = 1) {
print("Hello, world!")
}
Hello world
Usage
hello(x = 1)
Value
Prints 'Hello world'
Yet when I write an analogous script with Rcpp, the documentation is produced but no #usage section is written.
//' Hello, Rcpp!
//' #name rcpp_hello
//' #param CharVec Print x or not.
//' #export
#include <Rcpp.h>
using namespace Rcpp;
// This is a simple function using Rcpp that creates an R list
// containing a character vector and a numeric vector.
//
// Learn more about how to use Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
//
// and browse examples of code using Rcpp at:
//
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
List rcpp_hello(bool CharVec = true) {
CharacterVector x = CharacterVector::create("foo", "bar");
NumericVector y = NumericVector::create(0.0, 1.0);
List z = List::create(x, y);
if (CharVec) {
} else {
List z = List::create(y);
}
return z;
}
Hello, Rcpp!
Description
Hello, Rcpp!
Arguments
CharVec Print x or not.
I looked at the source code and documentation for dplyr::between, but there doesn't seem to be any special #usage section, yet the #usage section is present in the documentation.
I also looked at http://r-pkgs.had.co.nz/man.html and http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf and Ctrl-F'd for usage, but found nothing relevant.
I know I can add //' #usage rcpp_hello(CharVec = TRUE) in this particular case but the advantage of letting roxygen2 automate the process is that I can change the default arguments.
DESCRIPTION file:
Package: RcppSandBox
Type: Package
Title: What the Package Does (Title Case)
Version: 0.1.0
Author: Who wrote it
Maintainer: The package maintainer <yourself#somewhere.net>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: What license is it under?
Encoding: UTF-8
LazyData: true
Imports: Rcpp (>= 0.12.10)
LinkingTo: Rcpp
RoxygenNote: 6.0.1
Session info:
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252 LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C LC_TIME=English_Australia.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RcppSandBox_0.1.0 dplyr_0.5.0 RevoUtilsMath_10.0.0
loaded via a namespace (and not attached):
[1] compiler_3.4.0 magrittr_1.5 R6_2.2.2 assertthat_0.2.0 RevoUtils_10.0.4 DBI_0.6-1 tools_3.4.0
[8] tibble_1.3.0 Rcpp_0.12.10
You haven't needed to use #usage since Roxygen2 2.0 and 3.0.0 for R or Rcpp. The issue you are running into is your roxygen tags are not directly above the Rcpp attributes tag...
#include <Rcpp.h>
//' Hello, Rcpp!
//' #param CharVec Print x or not.
//' #export
// [[Rcpp::export]]
Rcpp::List rcpp_hello(bool CharVec = true) {
Rcpp::CharacterVector x = Rcpp::CharacterVector::create("foo", "bar");
Rcpp::NumericVector y = Rcpp::NumericVector::create(0.0, 1.0);
Rcpp::List z = Rcpp::List::create(x, y);
if (CharVec) {
} else {
Rcpp::List z = Rcpp::List::create(y);
}
return z;
}
Try the above. This also means you do not need the #name tag either...
Hello Bioconductor users,
I am playing around with ChipDb classes, in particular the illuminaHumanv4.db package. I am simply trying to create a table of annotations from that db using the select() method, as described in the help section.
I believe the only library needed to test this is
library("illuminaHumanv4.db")
The cols() function works fine
> cols(illuminaHumanv4.db)
[1] "PROBEID" "ENTREZID" "PFAM" "IPI" "PROSITE" "ACCNUM" "ALIAS" "CHR" "CHRLOC" "CHRLOCEND"
[11] "ENZYME" "MAP" "PATH" "PMID" "REFSEQ" "SYMBOL" "UNIGENE" "ENSEMBL" "ENSEMBLPROT" "ENSEMBLTRANS"
[21] "GENENAME" "UNIPROT" "GO" "EVIDENCE" "ONTOLOGY" "GOALL" "EVIDENCEALL" "ONTOLOGYALL" "OMIM" "UCSCKG"
The keytypes() function works fine too
> keytypes(illuminaHumanv4.db)
[1] "ENTREZID" "PFAM" "IPI" "PROSITE" "ACCNUM" "ALIAS" "CHR" "CHRLOC" "CHRLOCEND" "ENZYME"
[11] "MAP" "PATH" "PMID" "REFSEQ" "SYMBOL" "UNIGENE" "ENSEMBL" "ENSEMBLPROT" "ENSEMBLTRANS" "GENENAME"
[21] "UNIPROT" "GO" "EVIDENCE" "ONTOLOGY" "GOALL" "EVIDENCEALL" "ONTOLOGYALL" "PROBEID" "OMIM" "UCSCKG"
However, when I run the keys() function, I am getting the following error
> keys(illuminaHumanv4.db)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘keys’ for signature ‘"ChipDb"’
According to the documentation, the ChipDb class should inherit this function from the AnnotationDb class. This causes a error when I try to run the select() function, since one of the arguments to pass is generated by the keys() function.
I have updated my environment (R 3.0.1, bioconductor 2.12) and all my packages and here is my sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid splines parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] hgu95av2.db_2.9.0 BiocInstaller_1.10.2 gplots_2.11.3 KernSmooth_2.23-10 caTools_1.14 gdata_2.13.2
[7] gtools_3.0.0 hash_2.2.6 shiny_0.6.0 GO.db_2.9.0 illuminaHumanv4.db_1.18.0 org.Hs.eg.db_2.9.0
[13] RSQLite_0.11.4 DBI_0.2-7 annotate_1.38.0 AnnotationDbi_1.22.6 genefilter_1.42.0 WGCNA_1.27-1
[19] doParallel_1.0.3 iterators_1.0.6 foreach_1.4.1 MASS_7.3-27 reshape_0.8.4 plyr_1.8
[25] cluster_1.14.4 Hmisc_3.12-2 survival_2.37-4 flashClust_1.01-2 dynamicTreeCut_1.21 impute_1.34.0
[31] Biobase_2.20.1 BiocGenerics_0.6.0
loaded via a namespace (and not attached):
[1] AnnotationForge_1.2.2 bitops_1.0-5 codetools_0.2-8 compiler_3.0.1 digest_0.6.3 httpuv_1.0.6.3 IRanges_1.18.2
[8] lattice_0.20-15 Rcpp_0.10.4 RJSONIO_1.0-3 stats4_3.0.1 tools_3.0.1 XML_3.95-0.2 xtable_1.7-1
Let me know if anyone has run in the same problem recently.
Thank you!