Skip to content

Commit 4c7e7e0

Browse files
committed
main lint for code factor
1 parent 1185792 commit 4c7e7e0

File tree

5 files changed

+645
-658
lines changed

5 files changed

+645
-658
lines changed

R/main_vanilla.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#' @export
3737

3838
deme_inbreeding_spcoef_vanilla <- function(discdat,
39-
start_params = c(),
39+
start_params = NULL,
4040
lambda = 0.1,
4141
learningrate = 1e-3,
4242
m_lowerbound = 0,
@@ -124,8 +124,8 @@ deme_inbreeding_spcoef_vanilla <- function(discdat,
124124
# use efficient R functions to group pairs and wrangle data for faster C++ manipulation
125125
# get deme names and lift over sorted names for i and j
126126
demes <- sort(unique(c(discdat$deme1, discdat$deme2)))
127-
keyi <- data.frame(deme1 = demes, i = 1:length(demes))
128-
keyj <- data.frame(deme2 = demes, j = 1:length(demes))
127+
keyi <- data.frame(deme1 = demes, i = seq_len(length(demes)))
128+
keyj <- data.frame(deme2 = demes, j = seq_len(length(demes)))
129129

130130
# transform data w/ logit
131131
discdat <- discdat %>%
@@ -157,8 +157,8 @@ deme_inbreeding_spcoef_vanilla <- function(discdat,
157157
# versus a list with varying sizes (and eventually a more efficient for-loop)
158158
n_Kpairmax <- max(purrr::map_dbl(gendist$data, nrow))
159159
gendist_arr <- array(data = -1, dim = c(length(locats), length(locats), n_Kpairmax))
160-
for (i in 1:nrow(gendist)) {
161-
gendist_arr[gendist$i[i], gendist$j[i], 1:nrow(gendist$data[[i]])] <- unname(unlist(gendist$data[[i]]))
160+
for (i in seq_len(nrow(gendist))) {
161+
gendist_arr[gendist$i[i], gendist$j[i], seq_len(nrow(gendist$data[[i]]))] <- unname(unlist(gendist$data[[i]]))
162162
}
163163

164164
# normalize geodistances per user; NB have already removed self comparisons, so no 0s
@@ -191,13 +191,14 @@ deme_inbreeding_spcoef_vanilla <- function(discdat,
191191
if (length(unique(unlist(x))) != 1) {
192192
stop("deme1 and deme2 have different geodistances among P-sample combinations. Distances should all be same among samples")
193193
}
194-
return( unique(unlist(x)) ) # all same by unique
194+
# out
195+
unique(unlist(x)) # all same by unique
195196
}
196197
)
197198

198199
# upper tri
199200
geodist_mat <- matrix(data = -1, nrow = length(locats), ncol = length(locats))
200-
for (i in 1:nrow(geodist)) {
201+
for (i in seq_len(nrow(geodist))) {
201202
geodist_mat[geodist$i[i], geodist$j[i]] <- geodist$data[i]
202203
}
203204
diag(geodist_mat) <- 0

R/utils.R

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ update_progress <- function(pb_list, name, i, max_i) {
3232
#' @noRd
3333
# no export because simple
3434
logit <- function(p){
35-
return( log(p/(1-p)) )
35+
# out
36+
log(p/(1-p))
3637
}
3738

3839
#------------------------------------------------
@@ -43,7 +44,8 @@ logit <- function(p){
4344
#' @noRd
4445
# no export because simple
4546
expit <- function(p){
46-
return(1/(1+exp(-p)))
47+
# out
48+
1/(1+exp(-p))
4749
}
4850

4951
#------------------------------------------------
@@ -67,7 +69,8 @@ expand_pairwise <- function(discdf){
6769
colnames(discdfexpand) <- c("smpl2", "smpl1", "deme2", "deme1", "gendist", "geodist")
6870
discdfexpand <- rbind.data.frame(discdf, discdfexpand) # now have all pairwise possibilities
6971
discdfexpand <- discdfexpand[!duplicated(discdfexpand), ]
70-
return(discdfexpand)
72+
# out
73+
discdfexpand
7174
}
7275

7376

@@ -105,7 +108,7 @@ print.vanillaDISCresult <- function(x, ...) {
105108
#' @export
106109
summary.vanillaDISCresult <- function(object, ...) {
107110
# send summary only
108-
return(tidyout.vanillaDISCresult(object))
111+
tidyout.vanillaDISCresult(object)
109112
}
110113

111114

@@ -132,12 +135,10 @@ tidyout.vanillaDISCresult <- function(x) {
132135
# clean up
133136
#......................
134137
fis <- dplyr::bind_cols(x$deme_key, x$Final_Fis) %>%
135-
dplyr::select(-c("key")) %>%
138+
dplyr::select(-key) %>%
136139
magrittr::set_colnames(c("Deme", "DISC"))
137140

138141
# out
139-
ret <- list(Final_Fis = fis,
140-
Final_M = x$Final_m)
141-
return(ret)
142-
142+
list(Final_Fis = fis,
143+
Final_M = x$Final_m)
143144
}

man/deme_inbreeding_spcoef_vanilla.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)