├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── R └── caseconverter.R ├── README.md ├── caseconverter.Rproj ├── inst ├── media │ └── caseconverter.gif └── rstudio │ └── addins.dcf ├── man ├── camel_case.Rd ├── lower_case.Rd ├── snake_case.Rd └── upper_case.Rd └── tests ├── testthat.R └── testthat └── test-caseconverter.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^caseconverter\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.Rhistory$ 4 | ^\.gitignore$ 5 | ^\.travis\.yml$ 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | *.swp 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r 2 | 3 | language: R 4 | sudo: false 5 | cache: packages 6 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: caseconverter 2 | Version: 0.0.1.9000 3 | Title: RStudio Addin to convert text cases 4 | Description: An RStudio Addin to convert text cases to lower, upper, snake, and camel cases. 5 | Authors@R: person("Metin", "Yazici", email = "name@example.com", role = c("aut", "cre")) 6 | License: file LICENSE 7 | Imports: 8 | rstudioapi, 9 | snakecase 10 | Suggests: 11 | testthat (>= 2.0.0) 12 | LazyData: true 13 | ByteCompile: true 14 | Encoding: UTF-8 15 | RoxygenNote: 6.0.1 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Metin Yazici 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(camel_case) 4 | export(lower_case) 5 | export(snake_case) 6 | export(upper_case) 7 | importFrom(rstudioapi,documentSave) 8 | importFrom(rstudioapi,document_position) 9 | importFrom(rstudioapi,getActiveDocumentContext) 10 | importFrom(rstudioapi,modifyRange) 11 | importFrom(snakecase,to_lower_camel_case) 12 | importFrom(snakecase,to_snake_case) 13 | -------------------------------------------------------------------------------- /R/caseconverter.R: -------------------------------------------------------------------------------- 1 | 2 | ### WRAPPERS: 3 | 4 | #' Convert to upper case 5 | #' 6 | #' @param x character. 7 | #' @export 8 | upper_case <- function(x) { 9 | toupper(x) 10 | } 11 | 12 | #' Convert to lower case 13 | #' 14 | #' @param x character. 15 | #' @export 16 | lower_case <- function(x) { 17 | tolower(x) 18 | } 19 | 20 | #' Convert to snake case 21 | #' 22 | #' @param x character. 23 | #' @importFrom snakecase to_snake_case 24 | #' @export 25 | snake_case <- function(x) { 26 | snakecase::to_snake_case(x) 27 | } 28 | 29 | #' Convert to camel case 30 | #' 31 | #' @param x character. 32 | #' @importFrom snakecase to_lower_camel_case 33 | #' @export 34 | camel_case <- function(x) { 35 | snakecase::to_lower_camel_case(x) 36 | } 37 | 38 | ### ADDIN CALLS: 39 | 40 | upperCaseAddin <- function() { 41 | .case_call("upper_case") 42 | } 43 | 44 | lowerCaseAddin <- function() { 45 | .case_call("lower_case") 46 | } 47 | 48 | snakeCaseAddin <- function() { 49 | .case_call("snake_case") 50 | } 51 | 52 | camelCaseAddin <- function() { 53 | .case_call("camel_case") 54 | } 55 | 56 | #' @importFrom rstudioapi getActiveDocumentContext modifyRange document_position 57 | #' documentSave 58 | .case_call <- function(name) { 59 | call <- eval(parse(text = name)) 60 | context <- rstudioapi::getActiveDocumentContext() 61 | 62 | for (con in context[["selection"]]) { 63 | if (!con[["text"]] == '') { 64 | rstudioapi::modifyRange(location = con[["range"]], 65 | text = call(con[["text"]]), 66 | id = context[["id"]]) 67 | } else { 68 | rsrow <- con[["range"]][["start"]][["row"]] 69 | pos <- rstudioapi::document_position(c(rsrow, 1L), c(rsrow, Inf)) 70 | rstudioapi::modifyRange(location = pos, 71 | text = call(context[["contents"]][[rsrow]]), 72 | id = context[["id"]]) 73 | } 74 | } 75 | if (!context$path == '') { 76 | rstudioapi::documentSave(context$id) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # caseconverter 2 | 3 | [![Travis build status](https://travis-ci.org/strboul/caseconverter.svg?branch=master)](https://travis-ci.org/strboul/caseconverter) 4 | 5 | An RStudio Addin to convert text cases to lower, upper, snake, and camel cases. 6 | 7 | ![](inst/media/caseconverter.gif) 8 | 9 | ## Installation 10 | ``` 11 | # install.packages("devtools") 12 | devtools::install_github("strboul/caseconverter") 13 | ``` 14 | 15 | ## Reasoning 16 | I often find myself to have a comfortable (and interactive) way to convert the case of selected text in a file when working in the RStudio environment. 17 | 18 | ## See also 19 | + [snakecase](https://github.com/Tazinho/snakecase) package used for camel and snake case changes. 20 | 21 | ## License 22 | MIT 23 | -------------------------------------------------------------------------------- /caseconverter.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch 21 | PackageRoxygenize: rd,collate,namespace 22 | 23 | QuitChildProcessesOnExit: Yes 24 | -------------------------------------------------------------------------------- /inst/media/caseconverter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strboul/caseconverter/5bb40937e0ec602bccf3707ee714e53f49d649af/inst/media/caseconverter.gif -------------------------------------------------------------------------------- /inst/rstudio/addins.dcf: -------------------------------------------------------------------------------- 1 | Name: Make upper case 2 | Description: Converts text into upper case 3 | Binding: upperCaseAddin 4 | Interactive: false 5 | 6 | Name: Make lower case 7 | Description: Converts text into lower case 8 | Binding: lowerCaseAddin 9 | Interactive: false 10 | 11 | Name: Make snake case 12 | Description: Converts text into snake case 13 | Binding: snakeCaseAddin 14 | Interactive: false 15 | 16 | Name: Make camel case 17 | Description: Converts text into lower camel case 18 | Binding: camelCaseAddin 19 | Interactive: false 20 | -------------------------------------------------------------------------------- /man/camel_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caseconverter.R 3 | \name{camel_case} 4 | \alias{camel_case} 5 | \title{Convert to camel case} 6 | \usage{ 7 | camel_case(x) 8 | } 9 | \arguments{ 10 | \item{x}{character.} 11 | } 12 | \description{ 13 | Convert to camel case 14 | } 15 | -------------------------------------------------------------------------------- /man/lower_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caseconverter.R 3 | \name{lower_case} 4 | \alias{lower_case} 5 | \title{Convert to lower case} 6 | \usage{ 7 | lower_case(x) 8 | } 9 | \arguments{ 10 | \item{x}{character.} 11 | } 12 | \description{ 13 | Convert to lower case 14 | } 15 | -------------------------------------------------------------------------------- /man/snake_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caseconverter.R 3 | \name{snake_case} 4 | \alias{snake_case} 5 | \title{Convert to snake case} 6 | \usage{ 7 | snake_case(x) 8 | } 9 | \arguments{ 10 | \item{x}{character.} 11 | } 12 | \description{ 13 | Convert to snake case 14 | } 15 | -------------------------------------------------------------------------------- /man/upper_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caseconverter.R 3 | \name{upper_case} 4 | \alias{upper_case} 5 | \title{Convert to upper case} 6 | \usage{ 7 | upper_case(x) 8 | } 9 | \arguments{ 10 | \item{x}{character.} 11 | } 12 | \description{ 13 | Convert to upper case 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(caseconverter) 3 | 4 | test_check("caseconverter") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-caseconverter.R: -------------------------------------------------------------------------------- 1 | 2 | context("test caseconverter") 3 | 4 | test_that("upper case works", { 5 | expect_equal(upper_case("car"), "CAR") 6 | expect_equal(upper_case("TREE"), "TREE") 7 | expect_equal(upper_case("123class456"), "123CLASS456") 8 | expect_equal(upper_case("key_lock"), "KEY_LOCK") 9 | }) 10 | 11 | test_that("lower case works", { 12 | expect_equal(lower_case("dog"), "dog") 13 | expect_equal(lower_case("LIME"), "lime") 14 | expect_equal(lower_case("METHOD11"), "method11") 15 | expect_equal(lower_case("NEW_LINES"), "new_lines") 16 | }) 17 | 18 | test_that("snake case works", { 19 | expect_equal(snake_case("This is required."), "this_is_required") 20 | expect_equal(snake_case("getFinalData"), "get_final_data") 21 | expect_equal(snake_case("RunFastCode"), "run_fast_code") 22 | expect_equal(snake_case("draw.circle.angle"), "draw_circle_angle") 23 | expect_equal(snake_case("already_snake_case"), "already_snake_case") 24 | }) 25 | 26 | test_that("camel case works", { 27 | expect_equal(camel_case("An important method."), "anImportantMethod") 28 | expect_equal(camel_case("get_final_data"), "getFinalData") 29 | expect_equal(camel_case("DrawStringEmpty"), "drawStringEmpty") 30 | expect_equal(camel_case("draw.circle.angle"), "drawCircleAngle") 31 | expect_equal(camel_case("alreadyCamelCase"), "alreadyCamelCase") 32 | }) 33 | --------------------------------------------------------------------------------