Skip to content

Commit

Permalink
implement recs from package 'goodpractice'
Browse files Browse the repository at this point in the history
specifically move from c(1:x) to seq_len(x), and add BugReports to DESCRIPTION
  • Loading branch information
mjwestgate committed Nov 29, 2018
1 parent 7ec6b6c commit 523a286
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ Depends: R (>= 3.5.0)
Imports: ade4, plotly, shiny, shinydashboard, SnowballC, stringdist, tm, topicmodels, viridisLite, modeltools
License: GPL-3
URL: https://revtools.net
LazyData: true
BugReports: https://github.com/mjwestgate/revtools/issues
LazyData: true
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ renderPrint, renderPlot, renderUI, splitLayout,
validate, need,
showModal, modalDialog, removeModal, modalButton,
insertUI, removeUI,
shinyApp)
shinyApp, stopApp)
importFrom(shinydashboard,
sidebarMenu, menuItem, sidebarMenuOutput, renderMenu)
importFrom(stats, xtabs)
Expand Down
6 changes: 3 additions & 3 deletions R/bibliography-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ summary.bibliography <- function(object, ...){
source_freq <- sort(
xtabs(~ sources),
decreasing = TRUE
)[c(1:min(5, n_sources))]
)[seq_len(min(c(5, n_sources)))]
# put text together
result <- paste(
paste0(
Expand Down Expand Up @@ -75,14 +75,14 @@ print.bibliography <- function(x, n, ...){
n <- length_tr
}
}
text_tr <- format_citation(x[c(1:n)])
text_tr <- format_citation(x[seq_len(n)])
cat(paste(unlist(text_tr), collapse = "\n\n"))
}


'[.bibliography' <- function(x, n){
class(x) <- "list"
if(all(n %in% c(1:length(x))) == FALSE){
if(all(n %in% seq_len(length(x))) == FALSE){
stop("subset out of bounds")
}
z <- x[n]
Expand Down
4 changes: 2 additions & 2 deletions R/format_citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ format_citation.list <- function(
function(a){
dot.lookup <- a %in% "."
if(any(dot.lookup)){
a <- a[1:max(which(dot.lookup))]
a <- a[seq_len(max(which(dot.lookup)))]
}
return(paste(a, collapse = ""))
}
Expand Down Expand Up @@ -118,7 +118,7 @@ format_citation.data.frame <- function(
all(c("author", "year", source, "title") %in% names(data)) &
(details == TRUE)
){
data_list <- split(data, c(1:nrow(data)))
data_list <- split(data, seq_len(nrow(data)))
data_out <- unlist(lapply(data_list, function(a){
author_vector <- strsplit(a[['author']], " and ")[[1]]
if(length(author_vector) == 1){
Expand Down
10 changes: 5 additions & 5 deletions R/read_bibliography.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ prep_ris <- function(
if(delimiter == "endrow"){
# work out what most common starting tag is
z_dframe$ref <- c(0, cumsum(z_dframe$ris == "ER")[
c(1:(nrow(z_dframe)-1))]
seq_len(nrow(z_dframe)-1)]
) # split by reference

start_tags <- unlist(lapply(
Expand Down Expand Up @@ -183,7 +183,7 @@ prep_ris <- function(

# cleaning
z_dframe$ref <- c(0, cumsum(z_dframe$ris == "ER")[
c(1:(nrow(z_dframe)-1))]
seq_len(nrow(z_dframe)-1)]
) # split by reference
z_dframe <- z_dframe[which(z_dframe$text != ""), ] # remove empty rows
z_dframe <- z_dframe[which(z_dframe$ris != "ER"), ] # remove end rows
Expand Down Expand Up @@ -294,7 +294,7 @@ generate_bibliographic_names <- function(x){
rows <- which(nonunique_names == duplicated_names[i])
new_names <- paste(
nonunique_names[rows],
letters[1:length(rows)],
letters[seq_len(length(rows))],
sep = "_")
nonunique_names[rows] <- new_names
}
Expand Down Expand Up @@ -547,7 +547,7 @@ read_bib <- function(x){
entry_dframe <- entry_dframe[order(entry_dframe$row), c("tag", "value")]

if(any(entry_dframe$value == "}")){
entry_dframe <- entry_dframe[c(1:which(entry_dframe$value == "}")[1]-1), ]
entry_dframe <- entry_dframe[seq_len(which(entry_dframe$value == "}")[1]-1), ]
}
if(any(entry_dframe$value == "")){
entry_dframe <- entry_dframe[-which(entry_dframe$value == ""), ]
Expand Down Expand Up @@ -588,7 +588,7 @@ read_bib <- function(x){

# add type
x_final <- lapply(
c(1:length(x_final)),
seq_len(length(x_final)),
function(a, type, data){
c(type = type[a], data[[a]])
},
Expand Down

0 comments on commit 523a286

Please sign in to comment.