Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixex_#6665 #6672

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@
if (!is.null(by.x)) {
if (length(by.x)==0L || !is.character(by.x) || !is.character(by.y))
stopf("A non-empty vector of column names is required for `by.x` and `by.y`.")
if (!all(by.x %chin% nm_x))
stopf("Elements listed in `by.x` must be valid column names in x.")
if (!all(by.y %chin% nm_y))
stopf("Elements listed in `by.y` must be valid column names in y.")
if (!all(by.x %chin% nm_x)) {
missing_by_x = setdiff(by.x, nm_x)
stopf("Elements listed in `by.x` must be valid column names in x. Missing: %s", paste(missing_by_x, collapse = ", "))

Check warning on line 40 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=40,col=87,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 40 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=40,col=87,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
}
if (!all(by.y %chin% nm_y)) {
missing_by_y = setdiff(by.y, nm_y)
stopf("Elements listed in `by.y` must be valid column names in y. Missing: %s", paste(missing_by_y, collapse = ", "))

Check warning on line 44 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=44,col=87,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 44 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=44,col=87,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
}
by = by.x
names(by) = by.y
} else {
Expand All @@ -50,8 +54,12 @@
by = intersect(nm_x, nm_y)
if (length(by) == 0L || !is.character(by))
stopf("A non-empty vector of column names for `by` is required.")
if (!all(by %chin% intersect(nm_x, nm_y)))
stopf("Elements listed in `by` must be valid column names in x and y")
if (!all(by %chin% intersect(nm_x, nm_y))) {
missing_in_x = setdiff(by, nm_x)
missing_in_y = setdiff(by, nm_y)
stopf("Elements listed in `by` must be valid column names in x and y. Missing in x: %s. Missing in y: %s",

Check warning on line 60 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=60,col=113,[trailing_whitespace_linter] Remove trailing whitespace.

Check warning on line 60 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=60,col=113,[trailing_whitespace_linter] Remove trailing whitespace.
paste(missing_in_x, collapse = ", "), paste(missing_in_y, collapse = ", "))

Check warning on line 61 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=61,col=13,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 61 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=61,col=51,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 61 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=61,col=13,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists

Check warning on line 61 in R/merge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/merge.R,line=61,col=51,[paste_linter] toString(.) is more expressive than paste(., collapse = ", "). Note also glue::glue_collapse() and and::and() for constructing human-readable / translation-friendly lists
}
by = unname(by)
by.x = by.y = by
}
Expand Down
13 changes: 12 additions & 1 deletion man/setkey.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ haskey(x)
\arguments{
\item{x}{ A \code{data.table}. }
\item{\dots}{ The columns to sort by. Do not quote the column names. If \code{\dots} is missing (i.e. \code{setkey(DT)}), all the columns are used. \code{NULL} removes the key. }
\item{cols}{ A character vector of column names. For \code{setindexv}, this can be a \code{list} of character vectors, in which case each element will be applied as an index in turn. }
\item{cols}{ A character vector of column names. For \code{setindexv}, this can be a \code{list} of character vectors, in which case each element will be applied as an index in turn.

# Example: Single character vector of column names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! please move this to the \examples{} section

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure sir i will make a new pr for that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and sorry as i am new to this version control ,
I solved two issues under the same pr

DT = data.table(A = 5:1, B = letters[5:1], C = 10:6)
setindex(DT, A) # Set index using a single column
indices(DT) # View the indices

# Example: List of character vectors
setindexv(DT, list(c("A", "B"), c("B", "C"))) # Setting multiple indices
indices(DT) # View all indices
indices(DT, vectors = TRUE) # View indices as a list of vectors
}
\item{verbose}{ Output status and information. }
\item{physical}{ \code{TRUE} changes the order of the data in RAM. \code{FALSE} adds an index. }
\item{vectors}{ \code{logical} scalar, default \code{FALSE}; when set to \code{TRUE}, a \code{list} of character vectors is returned, each referring to one index. }
Expand Down
Loading