我正在尝试使用以下命令启动一个闪亮的应用程序。
Rscript -e "shiny::runApp('test-app', launch.browser=TRUE)"
Run Code Online (Sandbox Code Playgroud)
但是,我收到如下错误
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'htmltools' 0.4.0 is being loaded, but >= 0.4.0.9003 is required
Calls: :: ... getNamespace -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
Run Code Online (Sandbox Code Playgroud)
我确实检查了我的库文件夹并看到该htmltools包存在。
我也尝试过以下dependencies=TRUE
install.packages(pkgs,lib = "C:/Users/User/Desktop/data/library",repo = "https://cloud.r-project.org",dependencies=TRUE)
Run Code Online (Sandbox Code Playgroud)
这里的 pkgs 是一个包含必须安装的软件包列表的列表。
问题是相同的脚本在我的系统中工作,但在我同事的系统中不起作用。我该如何解决这个问题?
可以帮助我了解问题所在吗?
我可以从终端运行 perl 脚本“myperlscript.pl”,没有任何问题。但是,如果我尝试从 RStudio 中运行相同的 perl 脚本,则会出现以下错误:
command <- "myperlscript.pl outputfile.txt"
system2('perl', command)
Can't locate Sort/Fields.pm in @INC (you may need to install the Sort::Fields module)
(@INC contains:
/Library/Perl/5.28/darwin-thread-multi-2level
/Library/Perl/5.28
/Network/Library/Perl/5.28/darwin-thread-multi-2level
/Network/Library/Perl/5.28
/Library/Perl/Updates/5.28.2
/System/Library/Perl/5.28/darwin-thread-multi-2level
/System/Library/Perl/5.28
/System/Library/Perl/Extras/5.28/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.28) at myperlscript.pl line 4.
BEGIN failed--compilation aborted at myperlscript.pl line 4.
Run Code Online (Sandbox Code Playgroud)
我在 /Users/admin/perl5/perlbrew/perls/5.26.2/lib/site_perl/5.26.2 中安装了 Sort::Fields 模块,它使用终端工作正常,但似乎 RStudio 中的 perl 没有索引该目录对于 perl 模块 - 我尝试将它添加到 @INC 但不知何故我无法让它工作......有任何想法或想法吗?非常感谢帮助!
最好的,海科
我正在尝试安装 DEVTOOLS,但我不断收到错误消息。任何人都可以帮忙吗?2个错误如下所示
\nerror 1:package usethis was built under R version 4.0.5 \nError in loadNamespace\nerror 2:ERROR: lazy loading failed for package devtools\nRun Code Online (Sandbox Code Playgroud)\n这是我的代码
\ninstall.packages("blockmodeling", dependencies = TRUE)\ninstall.packages("devtools", dependencies = TRUE)\nlibrary(devtools)\ndevtools::install_github("aslez/concoR")\nRun Code Online (Sandbox Code Playgroud)\ninstall.packages("blockmodeling", dependencies = TRUE)\nWARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:\n\nhttps://cran.rstudio.com/bin/windows/Rtools/\nInstalling package into \xe2\x80\x98C:/Users/eslam/Documents/R/win-library/4.0\xe2\x80\x99\n(as \xe2\x80\x98lib\xe2\x80\x99 is unspecified)\ntrying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/blockmodeling_1.0.0.zip'\nContent type 'application/zip' length 410411 bytes (400 KB)\ndownloaded 400 KB\n\npackage \xe2\x80\x98blockmodeling\xe2\x80\x99 successfully unpacked …Run Code Online (Sandbox Code Playgroud) 我有一个包含许多基因的数据框(列是“基因”)。有些基因出现不止一次。我想对数据框进行子集化,其中只有出现多次的基因。换句话说,我想删除相对于“基因”列唯一的行。
我是网络抓取的新手,并且我已经成功地为多种不同类型的网站编写了函数,这些函数将我想要的信息收集到数据框架中。然而,话虽这么说,这些函数是在 Mac 上使用 RSelenium 开发的。当尝试在我的 Windows PC 上运行完全相同的功能时,它们失败了。
我认为该问题与 RSelenium 的启动方式有关。以下是我如何在每个不同的网络抓取功能中启动 RSelenium:
rs <- rsDriver(browser = "firefox", port = netstat::free_port())
remote <- rs$client
remote$navigate(url)
Run Code Online (Sandbox Code Playgroud)
在函数中执行此 R 代码后,将 Firefox 指定为 RSelenium 使用的浏览器时收到的错误如下:
Could not open firefox browser.
Client error message:
Undefined error in httr call. httr output: Failed to connect to localhost port 14415: Connection refused
Check server log for further details.
Error in checkError(res) :
Undefined error in httr call. httr output: length(url) == 1 is not TRUE
In addition: …Run Code Online (Sandbox Code Playgroud) 当我创建一个小数据框并在 RStudio 中将直接绘图运行到 PLOT 选项卡,然后尝试在 Shiny 中运行相同的概念时,直接绘图有效,并且 Shiny 绘图显示为空白并显示错误消息:
Warning in xy.coords(x, y, xlabel, ylabel, log) :
NAs introduced by coercion
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我将此代码尝试基于在网络上阅读和 Stack Overflow 中的先前答案,因此很接近,但我错过了一些隐式转换或其他内容。我只想使用 Shiny 来绘制数据框的两列。
library(shiny)
dfx <- data.frame(xx=c(1,2,3,4,5),
yy=c(2,4,6,8,10))
plot(dfx$xx, dfx$yy, xlim=c(0,6), ylim=c(0,10))
# the result in PLOTS in RStudio is a 5 point rising line graph as expected.
ui <- fluidPage(
headerPanel('my first shiny app'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(dfx)),
selectInput('ycol', 'Y Variable', names(dfx))
),
mainPanel(
plotOutput('plot1')
)
)
server <- function(input, output) {
output$plot1 …Run Code Online (Sandbox Code Playgroud) 我有一个美国电话号码向量,其中一些电话号码开头有一个前导“1”。如果数字长度为 11 位,则意味着第一个数字是我想要删除的“1”(至少在我的数据集中)。
phone <- c("1234567890", "1234567890", "5556456890", "5444567890", "19729772976")
Run Code Online (Sandbox Code Playgroud)
我使用删除了所有空格、标点符号和破折号
gsub("[- .)(+]|[a-zA-Z]*:?","", phone)
Run Code Online (Sandbox Code Playgroud)
如果字符串长度为 11 个字符,我不确定如何对其进行编码以删除第一个数字。或者换句话说,如果字符串具有一定长度,则删除向量中的第一个字符。
我在使用 R 进行一些实践时遇到了这个问题。所以这里是场景,
v = list(bob=c(2,3,5),bob=c("aa","bb"))
Run Code Online (Sandbox Code Playgroud)
我有一个名为的列表,v并且有两个列表元素都命名为bob. 当我编译它时,它不会给出任何错误。但最有趣的因素是,如果我尝试bob使用list name它进行打印会给我这样的结果,
> v$bob
[1] 2 3 5
Run Code Online (Sandbox Code Playgroud)
但是如果我bob使用attach()命令打印它会返回另一种方式。
> attach(v)
> bob
[1] "aa" "bb"
> detach(v)
Run Code Online (Sandbox Code Playgroud)
这两个不同的结果让我很好奇,请有人帮助理解下划线理论。
我正在尝试将 DNA 链的互补序列存储在向量中。它应该将“A”更改为“T”,将“C”更改为“G”,反之亦然,问题是,我需要这发生在第一个向量上并正确打印互补序列。这是我尝试过但被卡住的:
pilot_sequence <- c("C","G","A","T","C","C","T","A","T")
complement_sequence_display <- function(pilot_sequence){
complement_chain_Incom <- gsub("A", "T", pilot_sequence)
complement_chain <- paste(complement_chain_Incom, collapse = "")
cat("Complement sequence: ", complement_chain, "\n")
}
complement_chain_Incom <- gsub("A","T", pilot_sequence)
complement_chain <- paste(complement_chain_Incom, collapse= "")
complement_sequence_display(pilot_sequence)
Run Code Online (Sandbox Code Playgroud)
我得到的答案是:CGTTCCTTT,只有第二个和倒数第二个 T 是正确的,我该如何解决其余字母?
Pilot_sequence向量是字符类型,并且函数没有显示执行错误。
我有一个包含工资记录的 df 。对于每个重复的 PersonID-CalendarYear 组合,我想保留 WagesQ1:WagesQ4 列中的最高值。我还希望这些值都位于同一行。
例如,PersonID #49 有 3 行代表 2017 年。我想保留每个工资列中的最高值,这样我最终会得到 1 行代表 PersonID #49 和 2017 年。
到目前为止,我尝试了以下操作,但这会将每个 PersonID-CalendarYear 组合重复 4 次,这根本不是我想要的。
test <- Emp %>%
group_by(PersonID, CalendarYear) %>%
slice(which.max(WagesQ1),
which.max(WagesQ2),
which.max(WagesQ3),
which.max(WagesQ4))
Run Code Online (Sandbox Code Playgroud)
我在这里分享 df 的前 50 行:
structure(list(PersonID = c("30", "30", "30", "30", "30", "30",
"30", "30", "30", "30", "30", "30", "30", "30", "30", "30", "30",
"30", "30", "30", "30", "30", "36", "49", "49", "49", "49", "49",
"49", "49", "49", "49", "49", "49", …Run Code Online (Sandbox Code Playgroud)