Calculate total number of arguments enter into the function


#1

If i am making a function in R and i want to print how many character i have entered into an argument, please tell me how to make this function. Just to simply calculate and print the total number of characters are there in my argument or in my input


#2

I believe what you’re looking for is nchar:

f <- function(x) {
    nchar(x)
}

f(“apple”)


#3

Thankyou so much, but what if i want my argument as a string but not a character, also i want my input without any gap or commas.


#4

Can you provide a couple of examples of what you’re looking for?


#5

I am making a function in which it could calculate the total molecular weight of a protein. So, i have already entered or stored each molecular weights of every amino acids,

I want my function to read the argument or input like ABCDEF in this format. Please help me with this


#6

This seems to be the same question you are posting in the two other threads. Please refrain from cross-posting the same question in different topics, per the community guidelines.

https://community.rstudio.com/guidelines#keep-tidy

#7

Oops sorry, i will keep this in my mind